You need to sign in to do that
Don't have an account?
Shruthi MN 88
Send email when the Lead Owner changes
Can you help me write a handler class for the below code
public class SendEmailHandler {
List<Messaging.SingleEmailMessage> mails =
new List<Mesaging.SingleEmailMessage>();
{
for (Lead mylead : Trigger.new) {
if (mylead.Email != null && mylead.FirstName != null) {
Messaging.SingleEmailMessage mail =
new Messaging.SingleEmailMessage();
List<String> sendTo = new List<String>();
sendTo.add(mylead.Email);
mail.setToAddresses(sendTo);
// Step 3: Set who the email is sent from
mail.setReplyTo('abc@gmail.com');
mail.setSenderDisplayName('Lead has been created');
// (Optional) Set list of people who should be CC'ed
List<String> ccTo = new List<String>();
ccTo.add('abc@gmail.com');
mail.setCcAddresses(ccTo);
// Step 4. Set email contents - you can use variables!
mail.setSubject('Lead Owner has been changed');
String body = 'Dear ' + mylead.FirstName + ', ';
body += 'The Lead owner has been changed';
body += 'Please take care of the lead';
mail.setHtmlBody(body);
// Step 5. Add your email to the master list
mails.add(mail);
}
}
// Step 6: Send all emails in the master list
Messaging.sendEmail(mails);
}
}
4. Send email when the Lead Owner changes. Send email to the new lead owner and keep your respective Mentors in Cc of email.
( email body must have proper contain )
public class SendEmailHandler {
List<Messaging.SingleEmailMessage> mails =
new List<Mesaging.SingleEmailMessage>();
{
for (Lead mylead : Trigger.new) {
if (mylead.Email != null && mylead.FirstName != null) {
Messaging.SingleEmailMessage mail =
new Messaging.SingleEmailMessage();
List<String> sendTo = new List<String>();
sendTo.add(mylead.Email);
mail.setToAddresses(sendTo);
// Step 3: Set who the email is sent from
mail.setReplyTo('abc@gmail.com');
mail.setSenderDisplayName('Lead has been created');
// (Optional) Set list of people who should be CC'ed
List<String> ccTo = new List<String>();
ccTo.add('abc@gmail.com');
mail.setCcAddresses(ccTo);
// Step 4. Set email contents - you can use variables!
mail.setSubject('Lead Owner has been changed');
String body = 'Dear ' + mylead.FirstName + ', ';
body += 'The Lead owner has been changed';
body += 'Please take care of the lead';
mail.setHtmlBody(body);
// Step 5. Add your email to the master list
mails.add(mail);
}
}
// Step 6: Send all emails in the master list
Messaging.sendEmail(mails);
}
}
You can refer below code and make adjustments as per your requirement.
If this information helps, please mark the answer as best. Thank you
Can you help me execute it in the execuet anynomous window?
trigger SendEmilTrigger on Quote (after insert) {
Map<Id, Lead> oldLeadMap = Trigger.oldMap;
SendEmailTriggerHandler.sendEmailOnLeadOwnerChange(Trigger.new, oldLeadMap);
}
In your trigger, you are trying to call a method "sendEmailOnLeadOwnerChange" from a class named SendEmailTriggerHandler, but in the provided code snippet, the class name is SendEmailHandler.
You should match the class name in your trigger with the actual class name.
Example: Replace class name and method name with acutal names.
In the Execute Anonymous window, you can insert the following code to insert a Quote record. If this information helps, please mark the answer as best. Thank you