You need to sign in to do that
Don't have an account?
Thakkar Parth
Can i use setOrgWideEmailAddressId(Id
Can i use setOrgWideEmailAddressId(Id) to send the FROM address in my case. My requirement is to send an email FROM Owner to the particular Lead when the Lead Status is changed.
I've enabled Org Wide Addressed in the Org Setup. Please help.
I've enabled Org Wide Addressed in the Org Setup. Please help.
trigger UpdateLeadStatus on Lead (after update) { Map <Id, String> leadsOwner = new Map <Id, String> (); // Go through every lead in the trigger for (Lead lead : trigger.new) { // Check if the status has been changed if (lead.Status != trigger.oldMap.get(lead.Id).Status) { // get the owner ID's that have been affected leadsOwner.put(lead.ownerId, null); } } // Map the owner ID to it's email address for (User owner : [SELECT Id, Email FROM User WHERE Id = :leadsOwner.keySet()]) { leadsOwner.put(owner.Id, owner.Email); } List <Messaging.SingleEMailMessage> emails = new List <Messaging.SingleEMailMessage> (); // Go again through every lead in the trigger for (Lead lead : trigger.new) { // Only work with leads that have owners mapped to their email addresses (only those ones have their status changed) if (leadsOwner.get(lead.OwnerId) != null) { // Create an email message and add it to the list Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); List <String> toAddresses = new List <String> {leadsOwner.get(lead.OwnerId)}; mail.setToAddresses(toAddresses); mail.setSubject('Automated Email : Lead Status Updated'); String body = 'The status has been changed on the lead record with ID ' + lead.Id; mail.setPlainTextBody(body); emails.add(mail); } } Messaging.sendEmail(emails); }
First you need to query org wid email address as
If this helps, mark this as best answer.
thanks,
N.J
Thanks,
N.J