function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
downloadingdownloading 

Uploading A file

Hi , 

I wanna upload a file from my local machine to salesforce account, 

Could any one help me with the sample code how would i achieve this

 

Thank You

Best Answer chosen by Admin (Salesforce Developers) 
TechOwlTechOwl

Are you doing this with a Visualforce page?

 

If you are then here are a couple of URLs to look at for slightly different examples:

 

http://blog.jeffdouglas.com/2010/04/28/uploading-an-attachment-using-visualforce-and-a-custom-controller/

 

http://salesforcetrekbin.blogspot.com/2010/04/visualforce-file-upload-for-any-sobject.html

 

All Answers

TechOwlTechOwl

Are you doing this with a Visualforce page?

 

If you are then here are a couple of URLs to look at for slightly different examples:

 

http://blog.jeffdouglas.com/2010/04/28/uploading-an-attachment-using-visualforce-and-a-custom-controller/

 

http://salesforcetrekbin.blogspot.com/2010/04/visualforce-file-upload-for-any-sobject.html

 

This was selected as the best answer
downloadingdownloading

HI, 

i am able to uplaod a file , but now i would like to view the uploaded content 

How could i achieve that ..

 Thank You...

Richa KRicha K

Hi,

In addition to the code given by Jeff, please add the following snippets :

 

In Class :

public list<Document> lstDoc = new list<Document>();
public list<Document> getNewFun()
  {
      for(Document doc : [select FolderId, Name, Url from Document])
      {
        lstDoc.add(doc);
      }
      System.debug('hhiiiiiiiiiiiii'+lstDoc);
      return lstDoc;
      
  }

 

In Page :

<apex:pageBlock title="Documents">

    <apex:pageBlockTable value="{!NewFun}" var="aDoc" width="100%" >
     
     <apex:column >
      <apex:facet name="header"><b>Document Name</b></apex:facet>
     {!aDoc.Name}
     </apex:column>
     
     <apex:column >
     <apex:outputLink value="https://ap1.salesforce.com/{!aDoc.Id}">https://ap1.salesforce.com/{!aDoc.Id}</apex:outputLink> 
      
   
     </apex:column>
     
       <apex:column >
      <apex:facet name="header"><b>Document Folder ID</b></apex:facet>
      {!aDoc.FolderId}
     </apex:column>

   </apex:pageBlockTable>                

 </apex:pageBlock>

 This will show you the document list alongwith the links to the documents.

Hope this will help!

surekhasurekha

Hi...

 

can u plz explain the program..

actualy i tried the program..u posted that link..

but its not saved....it displays error...

 

http://blog.jeffdouglas.com/2010/04/28/uploading-an-attachment-using-visualforce-and-a-custom-contro...

 

Thanks & Regards

   surekha