We have 2 types of email service.
- Outbound Email: If we are sending email from salesforce to external system, then we call it as outbound email services.
- Inbound Email: If we are sending email from external system to salesforce, then we call it as Inbound email services.
All the classes & methods required to handle the email services are defined in messaging namespace
Outbound message
- We can able to send the Email context or plain text or HTML format.
- We can also attach email templates & Attachments to the email.
- We have 2 ways to send the outbound 1
- messaging.singleEmailMessage
- 2.Messaging.MassEmailMessage
messaging.singleEmailMessage
Methods
- setToAddresses(List<string> emailAddress): To specify the To Address interms of string Array or List. Note: The maximum allowed ToAddresses is 100.
- setCCAddresses(List<string>emailAddress):This method is used to set one or more CC Email Addresses. Note: The maximum Allowed is 25.
- setBCCAddress(List<string>emailAddress):This method is used to set one or more BCC Email Addresses. Note : The maximum Allowed is 25.
- setReplyTo(string):
- setSenderDisplayName(string):This method is used to set the display name of sender in email .Example : ‘’SalesforceCodes’’.
- setSubject(string EmailSubject):
- setPlainTextBody(string Email context): [set format in plain]
- setHTMLBody(string email HTML context).
Note: If we want to send the email we have to use senderEmail(List<Email>) method defined in messaging class.
Syntaxes
- 1.Messaging.Email[] emails = new messaging.Email[]{email1,email2,….};
- Messaging.sendEmail(emails);
- 2. Messaging.sendEmail(List<stringEmailMessageObject> emails);
- This method is defined in the messaging namespace.
- This method is used to send the single/multiple email messages.
Outbound Email with PDF Attachments
Messaging.EmailFileAttachment :
This is predefined class which is used to create PDF Attachment for Emails. Email FileAttachment is used in singleEmailMessage to specify attachment passed is,as part of the Email outbound message.
Methods of EmailFileAttachment :
- 1. setFileName(FileName) :
- This method is used to set the name of the email Attachment file.
- 2. setBody(Bold) :
- This method is used to set the body of the attachment is the format of bold.
- 3.setContextType(Context Type):
- This will specify the context type of the email Attachment.
Email Template As Body
Email templates are attachment as body of the email only when we want to send email to
- Lead.
- Contact.
- User.
setTargetObjectId(ID of the user/contact): When we want to send the email template particular user/contact/Lead .
SetTargetObjectIds(List <id> contacts/users/Leads): This method can be used is MassEmailMassage only.
SetWhatId(Id): This method is optional. Used only if forget object Id is Contact id. In the Email Template if you are using data from any record ,the that record id should be pressed as WhatId.
Messaging.MassEmailMessage
- This class is used to send the Bulk Email to the salesforce users (contacts/users/Leads).
- We can send email up to 250 users in a single instance.
- We have to add all the user ID’s is the list n order to send the Email Notification.
Note : While sending the email , we can use Email Templates also
Methods
- setTargetObjectIDs(List<ID>)
- setEmailTemplateID(EmailTemplate ID)
Inbound Email Services :
Syntax
Messaging.InboundEmailResult handleInboundEmail(messaging.InboundEmail email,messaging.InboundEnvelope envelope){ }
messaging.InboundEmailresult : This class specifies weather inbound email is handled successfully or not.
Messaging.InboundEmail : This Class Contains all data received from Inbound Email.
Messaging.InboundEnvelope
No comments:
Post a Comment