You need to sign in to do that
Don't have an account?
akkk
how to send a email when status is approved ?
Hi all ,
i have code
trigger sampletrigger on object(after insert,after update)
{
List<object2>obj2list = new list<object2>();
for(object1 obj1 : trigger.new)
{
If(obj1.status =='approved')
{
Object2 obj2 = new object2();
Obj2.FirstNsme = obj1.firstname;
Obj2.lastnsme = obj1.lastname;
obj2.city = obj1.city;
obj2.status = obj1.status;
Obj2list.add(obj2);
}
}
Database.insert(obj2list,false);
}
the question is that how to send a email with Template if the Status is Approved ?
i have code
trigger sampletrigger on object(after insert,after update)
{
List<object2>obj2list = new list<object2>();
for(object1 obj1 : trigger.new)
{
If(obj1.status =='approved')
{
Object2 obj2 = new object2();
Obj2.FirstNsme = obj1.firstname;
Obj2.lastnsme = obj1.lastname;
obj2.city = obj1.city;
obj2.status = obj1.status;
Obj2list.add(obj2);
}
}
Database.insert(obj2list,false);
}
the question is that how to send a email with Template if the Status is Approved ?
You can use workflow rule instead of trigger to send an email alert based on the based on certain criteria.
Create workflow rule with following formula
And create an email alert with required template.
Please refer below link which might help you in this
https://help.salesforce.com/articleView?id=customize_wf.htm&type=5 (https://help.salesforce.com/articleView?id=customize_wf.htm&type=5)
https://success.salesforce.com/answers?id=9063A000000sx0AQAQ
Hope this helps you
Let me know if this helps you. Kindly mark it as solved so that it may help others in future.
Thanks and Regards
As you have the above trigger code you can call apex class from the same code by passing the id as parameter. In the apex class use SingleEmailMessage to send email using email template.
Try refering this code for sending email using Email temaplate
References:
https://medium.com/@tekie.touch/sending-emails-with-template-using-apex-in-salesforce-1f343b0c532c
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_email_outbound_single.htm
Hope this helps! Please mark as best if it does.
Thanks
I missed syntax would be Classname.methodname(); in trigger. You can try bulkifying code once it works.
Apex class would be: Thanks