You need to sign in to do that
Don't have an account?

Email through trigger
Can any body tell how to send an email through trigger in detail
You need to sign in to do that
Don't have an account?
Can any body tell how to send an email through trigger in detail
Hi,
Try this
Hi,
Try this
trigger EmailSendingToOwner on ObjectName(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
You can go through This documentaion on outbound email sending through apex, howevere i think it is not a good practice to send emails from trigger(as there exists limit on how many emails you can send, i think you can only upto 10 of those). See this for governer limit Govener limits
You can use workflow if your logic is implementable through workflow.
Thanks,
can you tell me the following error which i encountered while implemnting above code
Review all error messages below to correct your data.
Apex trigger EmailSendingToOwner caused an unexpected exception, contact your administrator: EmailSendingToOwner: execution of AfterUpdate caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_SAVE_AS_ACTIVITY_FLAG, saveAsActivity must be false when sending mail to users.: []: Trigger.EmailSendingToOwner: line 6, column 1
You can add the blue colored line and see what happens
trigger EmailSendingToOwner on ObjectName(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);
email.setSaveAsActivity(false);
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