UPLOADING A DOCUMENT INTO SALESFORCE USING VISUALFORCE | Techila
1985
single,single-post,postid-1985,single-format-standard,ajax_updown_fade,page_not_loaded,,qode_grid_1300,footer_responsive_adv,hide_top_bar_on_mobile_header,qode-content-sidebar-responsive,qode-theme-ver-9.4.2,bridge,wpb-js-composer js-comp-ver-4.12,vc_responsive
 

UPLOADING A DOCUMENT INTO SALESFORCE USING VISUALFORCE

UPLOADING A DOCUMENT INTO SALESFORCE USING VISUALFORCE

UPLOADING A DOCUMENT INTO SALESFORCE USING VISUALFORCE

In this article we will understand the procedure to upload a file into “Documents” using a Visualforce Page. You can upload a file and save it as an attachment against a record I believe, but I am not sure how to do this. Hence, this topic would only cover uploading a file to “Documents” under a folder you desire.

I actually had to upload a file against a record. I uploaded the file into Documents, and then stored the reference of the file as a Field in the record. This way I can access the document from the record directly at a later point.

<apex:inputfile> is the tag that is used to upload a file.

Code Sample:

Create the following Visualforce Page

<apex:page controller=”UploadDoc”>

<apex:form>

  <apex:sectionHeader title=”Upload a Document into Salesforce”/>

  <apex:pageblock>

      <apex:pageblocksection columns=”1″>

          <apex:inputfile value=”{!myimage.body}” filename=”{!myimage.Name}” />

          <apex:commandbutton value=”Save” action=”{!Savedoc}”/>

      </apex:pageblocksection>

  </apex:pageblock>  

</apex:form>

</apex:page>

The controller would be named “UploadDoc” and will have the following code

public class UploadDoc

{

Public Document mydoc;

    Public Document getmyimage()

    {

        mydoc = new Document();

        return mydoc;

    }

    Public Pagereference Savedoc()

    {

        mydoc.folderid = UserInfo.getUserId(); // Stores in the currennt users “My Personal Documents” folder

        //mydoc.folderid = ‘any other id you want here’; // Fetch Id dynamically by using [Select Id from Folder where Name=’My Images’]. Specifying a FolderId is mandatory

        insert mydoc;

        return NULL;

    }  

}

Courtesy:  http://www.forcetree.com/2011/01/uploading-document-into-salesforce.html
http://panthergraphicsla.com/images/Upload.png

“Explore – Techila Global Services, A Salesforce development company”

Author: techila

No Comments

Post A Comment