function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sankumsankum 

how to send email from triggers

hi 

i need to send the email from trigger!

my requirement is 

when a recored is updated in lead object the email is send to the owner or admin... BY using trigger only 

how it is?

 

     thanks in advance

        KIRAN

 

souvik9086souvik9086

Hi,

 

Try this

 

trigger EmailSendingToOwner on Lead (after update) {
EmailTemplate emailTemp = [select id,name from EmailTemplate].get(0);
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setTargetObjectId(Trigger.new[0].OwnerId);
email.setTemplateId(emailTemp.id);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
}

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

Yoganand GadekarYoganand Gadekar

hi,

 

I would suggest to avoid sending emails using outbound email codes in trigger as this may hit your governer limits,

 

I think you have a limit on emails you can send, go through This documentaion to know more about about govener limits wrt emails...

 

thanks,