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
Tushar SethTushar Seth 

How to Upload file from desktop as an Attachment to Email in Salesforce

Hi,

Can we upload desktop file as an Attachment into the Email through Apex code....

I have searched alot but couldn't get the exact answer for that....

 

If anyone know any solution to this then please reply to this post ASAP.....

 

 

Tushar SethTushar Seth

Just to elaborate - I need to build this functionality. There is a Visualforce page with the following fields -

a) Sender email address

b) eMail Subject

c) eMail Body

d) Button to open file open dialog box to allow the user to select attachments.

I have completed a, b and c. But I am not familiar how to d.

 

kiranmutturukiranmutturu

u have to use simply like this

 

<apex:page standardController="Document" extensions="documentExt">
    <apex:messages />
    <apex:form id="theForm">
      <apex:pageBlock>
          <apex:pageBlockSection>
            <apex:inputFile value="{!document.body}" filename="{!document.name}"/>
            <apex:commandButton value="Save" action="{!save}"/>
          </apex:pageBlockSection>
       </apex:pageBlock>
    </apex:form>
</apex:page>
                
/*** Controller ***/
public class documentExt {
    public documentExt(ApexPages.StandardController controller) {
        Document d = (Document) controller.getRecord();
        d.folderid = UserInfo.getUserId(); //this puts it in My Personal Documents
    }                 
}