You need to sign in to do that
Don't have an account?
Pulse Centers
Send a single email to multiple users with Apex class
I'm trying to add another recipient to an email button and can not seem to get it to work. Below is the Apex code for the current button, please let me know what I need to change to add a second recipient.
global class SendPurchaseOrderEmail {
WebService static void sendEmail(String poId) {
List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
String theTemplate = [SELECT Id FROM EmailTemplate WHERE DeveloperName = 'Purchase_Order_With_Items'].Id;
User theUser = [SELECT Id FROM User WHERE Name = 'user name goes here'];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setSaveAsActivity(false);
mail.setTemplateId(theTemplate);
mail.setWhatId(poId);
mail.setTargetObjectId(theUser.Id);
emails.add(mail);
Messaging.sendEmail(emails);
}
}
global class SendPurchaseOrderEmail {
WebService static void sendEmail(String poId) {
List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
String theTemplate = [SELECT Id FROM EmailTemplate WHERE DeveloperName = 'Purchase_Order_With_Items'].Id;
User theUser = [SELECT Id FROM User WHERE Name = 'user name goes here'];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setSaveAsActivity(false);
mail.setTemplateId(theTemplate);
mail.setWhatId(poId);
mail.setTargetObjectId(theUser.Id);
emails.add(mail);
Messaging.sendEmail(emails);
}
}
Try below code and let me know if it works.
please refer below link for more details.
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_sendemail.htm
Best Regards,
-Vivek
All Answers
Try below code and let me know if it works.
please refer below link for more details.
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_sendemail.htm
Best Regards,
-Vivek
String theTemplate = [SELECT Id FROM EmailTemplate WHERE DeveloperName ='Purchase_Order_With_Items'].Id;
in the query from where did you get the value ' DeveloperName ='Purchase_Order_With_Items'].Id; '
Thank You.