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
vinod kumar 364vinod kumar 364 

Attaching file to salesforce record how to write a filter in vf page to select salesforce documents and my computer documents



Enter code here
User-added image
User-added image
VF Page:


<table width="500px" align="center" cellpadding="2" cellspacing="2">
           <tr>
                    <td colspan="4" align="center"><font size="3"><b>Upload Documents</b></font><br />
                    <br />
                    <br /></td>
                </tr>
         <tr><td> </td>
                <td>   <apex:inputFile id="fileToUpload" value="{!fileBody}" filename="{!fileName}" /> </td>
                <td><apex:outputText value="{!filename}"></apex:outputtext></td>
          <td> <apex:commandButton value="Upload Attachment" action="{!uploadattachment1}"/>  </td>  
                </tr>

              <tr>
               <td> </td>
             <td>  <apex:inputFile id="fileToUpload2" value="{!fileBody2}" filename="{!fileName2}" />  </td>
              <td><apex:outputText value="{!filename2}"></apex:outputtext></td>
           <td> <apex:commandButton value="Upload Attachment" action="{!uploadattachment2}"/>  </td>      
                </tr>
                <tr>
                <td> </td>
             <td>   <apex:inputFile id="fileToUpload3" value="{!fileBody3}" filename="{!fileName3}" /> </td>
              <td><apex:outputText value="{!filename3}"></apex:outputtext></td>
           <td> <apex:commandButton value="Upload Attachment" action="{!uploadattachment3}"/>  </td>    
                </tr> 
            </table>  





APEX Code:




 public void uploadattachment1() 
      {
       if(fileBody != null && fileName != null)
        {
          Attachment myAttachment1  = new Attachment();
          myAttachment1.Body = fileBody;
          myAttachment1.Name = fileName;
          myAttachment1.ParentId = cid;        
           insert myAttachment1;
        }
      }

 I need an option in VF page to help me choose a file from salesforce and external computer.
Raj VakatiRaj Vakati
Hi Vinod , 
Use this code 
List<Document> documents = [SELECT Id, Name, Body FROM Document WHERE Name='Test'];
        Folder dummyFolder = [SELECT Id FROM Folder LIMIT 1];
        Document myDocument;
            myDocument = new Document();
            myDocument.FolderId = dummyFolder.id;
            myDocument.Body = EncodingUtil.base64Decode(...);
            myDocument.ContentType = '---';
            myDocument.Name = '----';
            insert myDocument;