Home Custom Email Template Creating Email Templates and Automatically Sending Emails

Solution

  1. Create an appropriate email template through the email template wizard. Salesforce.com supports multiple email template types. This examples assumes you are using a Visualforce email template. To create a Visualforce email template, you must have the “Customize Application” permission enabled.
  2. Send an automatic email response to the job applicant’s incoming email using the Messaging.sendEmail static method to process outbound email messages.

    First, create a Visualforce email template:

    1. Click Setup | Email | My Templates. If you have permission to edit public templates, click Setup | Communication Templates | Email Templates.
    2. Click New Template.
    3. Choose Visualforce and click Next.
    4. Choose a folder in which to store the template.
    5. Select the Available For Use checkbox if you would like this template offered to users when sending an email.
    6. Enter an Email Template Name.
    7. If necessary, change the Template Unique Label.
    8. Select an Encoding setting to determine the character set for the template.
    9. Enter a Description of the template. Both template name and description are for your internal use only.
    10. Enter the subject line for your template in Email Subject.
    11. In the Recipient Type drop-down list, select the type of recipient that will receive the email template.
    12. Optionally, in the Related To Type drop-down list, select the object from which the template will retrieve merge field data.
    13. Click Save.
    14. Click Edit Template.
    15. Enter markup text for your Visualforce email template.
    16. Click Save to save your changes and view the details of the template, or click Quick Save to save your changes and continue editing your template. Your Visualforce markup must be valid before you can save your template.
      The maximum size of a Visualforce email template cannot exceed 1 MB.
    This sample Visualforce email template creates an interview invitation:
          Dear {!relatedTo.Candidate__r.First_Name__c}            {!relatedTo.Candidate__r.Last_Name__c}    Thank you for your interest in the position           {!relatedto.Position__r.name}    We would like to invite you for an interview.   Please respond to the attached invitation.    Regards,  Company          BEGIN:VCALENDAR  METHOD:REQUEST  BEGIN:VTIMEZONE  TZID:(GMT-08.00) Pacific Time (US and Canada)  BEGIN:STANDARD  DTSTART:16010101T020000  TZOFFSETFROM:-0700  TZOFFSETTO:-0800  RRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=11;BYDAY=1SU  END:STANDARD  BEGIN:DAYLIGHT  DTSTART:16010101T020000  TZOFFSETFROM:-0800  TZOFFSETTO:-0700  RRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=3;BYDAY=2SU  END:DAYLIGHT  END:VTIMEZONE  BEGIN:VEVENT  DTSTAMP:20090921T202219Z  DTSTART;TZID="(GMT-08.00) Pacific Time           (US and Canada)":20090923T140000  SUMMARY:Invitation: Interview Schedule @ Wed Sep 23 2pm - 4pm   ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;          CN="{!recipient.name}":MAILTO:{!recipient.email}  ORGANIZER;CN="John.Smith":MAILTO:[email protected]  LOCATION:Hawaii   DTEND;TZID="(GMT-08.00) Pacific Time           (US and Canada)":20090923T160000  DESCRIPTION: You are invited to an inverview          \NInterview Schedule          \NWed Sep 23 2pm - 4pm           (Timezone: Pacific Time) \NCalendar: John Smith           \N\NOwner/Creator: [email protected]             \NYou will be meeting with these people:          CEO Bill Jones,           Office Manager Jane Jones  \N  SEQUENCE:0  PRIORITY:5  STATUS:CONFIRMED  END:VEVENT  END:VCALENDAR          
    Then, send an automatic email response to the job applicant's incoming email. This example uses a Visualforce email template:



      // In a separate class so that it can be used elsewhere  Global class emailHelper {    public static void sendEmail(ID recipient, ID candidate) {      //New instance of a single email message   Messaging.SingleEmailMessage mail =               new Messaging.SingleEmailMessage();     // Who you are sending the email to     mail.setTargetObjectId(recipient);       // The email template ID used for the email     mail.setTemplateId('00X30000001GLJj');                 mail.setWhatId(candidate);         mail.setBccSender(false);     mail.setUseSignature(false);     mail.setReplyTo('[email protected]');     mail.setSenderDisplayName('HR Recruiting');     mail.setSaveAsActivity(false);       Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });        }    }    


    Source : http://developer.force.com/cookbook/recipe/creating-email-templates-and-automatically-sending-emails
    https://login.salesforce.com/help/doc/en/creating_visualforce_email_templates.htm

    You may also like

    Leave a Comment