Email Messaging from Salesforce
SingleEmailMessage & MassEmailMessage classes are provided by Salesforce, which can be used to send an email or email in bulk to the users.
First of all we need to create a Helper class,we will call this class using Trigger, whenever the condition met, the trigger will call this Helper class, and all the stuffs whatever we are doing, will be in helper class. We are using an email template too.
Here is the Helper class named "HelperContactTrigger"
Now we will call the above class in our trigger named "SendEmailToAccount"
Here is the trigger, just paste this in your Account's Trigger
First of all we need to create a Helper class,we will call this class using Trigger, whenever the condition met, the trigger will call this Helper class, and all the stuffs whatever we are doing, will be in helper class. We are using an email template too.
Here is the Helper class named "HelperContactTrigger"
public with sharing class HelperContactTrigger {
//static method
public static List sendEmail(List contacts) {
//query on template object
EmailTemplate et=[Select id from EmailTemplate where name=:'Sales: New Customer Email'];
//list of emails
List emails = new List();
//loop
for(Contact con : contacts){
//check for Account
if(con.AccountId == null && con.Email != null){
//initiallize messaging method
Messaging.SingleEmailMessage singleMail = new Messaging.SingleEmailMessage();
//set object Id
singleMail.setTargetObjectId(con.Id);
//set template Id
singleMail.setTemplateId(et.Id);
//flag to false to stop inserting activity history
singleMail.setSaveAsActivity(false);
//add to the list emails
emails.add(singleMail);
}
}
//send mail
Messaging.sendEmail(emails);
return contacts;
}
}
//static method
public static List
//query on template object
EmailTemplate et=[Select id from EmailTemplate where name=:'Sales: New Customer Email'];
//list of emails
List
//loop
for(Contact con : contacts){
//check for Account
if(con.AccountId == null && con.Email != null){
//initiallize messaging method
Messaging.SingleEmailMessage singleMail = new Messaging.SingleEmailMessage();
//set object Id
singleMail.setTargetObjectId(con.Id);
//set template Id
singleMail.setTemplateId(et.Id);
//flag to false to stop inserting activity history
singleMail.setSaveAsActivity(false);
//add to the list emails
emails.add(singleMail);
}
}
//send mail
Messaging.sendEmail(emails);
return contacts;
}
}
Now we will call the above class in our trigger named "SendEmailToAccount"
Here is the trigger, just paste this in your Account's Trigger
Trigger SendEmailToAccount on Contact (after insert, after update) {
if(Trigger.isAfter){
if(Trigger.isInsert || Trigger.isUpdate){
//helper class for single email but bulk messages
HelperContactTrigger.sendEmail(trigger.new);
}
}
if(Trigger.isAfter){
if(Trigger.isInsert || Trigger.isUpdate){
//helper class for single email but bulk messages
HelperContactTrigger.sendEmail(trigger.new);
}
}
Create a Contact record and fill the Email field with your email and save it.
You will receive an email from the your salesforce.
This comment has been removed by the author.
ReplyDeleteInspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..Keep update more information..
ReplyDeleterpa training in electronic-city | rpa training in btm | rpa training in marathahalli | rpa training in pune
Awesome article. It is so detailed and well formatted that i enjoyed reading it as well as get some new information too.
ReplyDeleteData Science course in rajaji nagar | Data Science with Python course in chenni
Data Science course in electronic city | Data Science course in USA
Data science course in pune | Data science course in kalyan nagar
I appreciate that you produced this wonderful article to help us get more knowledge about this topic. I know, it is not an easy task to write such a big article in one day, I've tried that and I've failed. But, here you are, trying the big task and finishing it off and getting good comments and ratings. That is one hell of a job done!
ReplyDeletePython training in marathahalli | Python training institute in pune
It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
ReplyDeletejava training in jayanagar | java training in electronic city
java training in chennai | java training in USA
Thanks for sharing this information admin. Continue sharing more like this.
ReplyDeleteAngularjs course in Chennai
Angularjs Training in Chennai
Angularjs Training institute in Chennai
AWS course in Chennai
Robotics Process Automation Training in Chennai
UiPath Training in Chennai
This is a very helpful blog for one who needs to learn in a short span of time.
ReplyDeleteSpoken English in Adyar
Spoken English Classes in Palavakkam
Spoken English Classes in Besant Nagar
Spoken English Institute near me
Spoken English in Porur
Spoken English Class in Virugambakkam
Spoken English Training in DLF
This is really too useful and have more ideas and keep sharing many techniques. Eagerly waiting for your new blog keep doing more.
ReplyDeleteAws Cloud Training in Bangalore
Aws Coaching Centre in Bangalore
cloud computing training institutes in bangalore
best cloud computing training in bangalore
cloud computing certification in bangalore
Nice post. I learned some new information. Thanks for sharing.
ReplyDeleteGuest posting sites
Technology
your blog information's are really creative and It contains full of new innovative ideas.
ReplyDeletethank you for sharing with us.please update more data.
Salesforce Training in Vadapalani
Salesforce Training in Amjikarai
Salesforce Training in Thirumangalam
Salesforce Training courses near me
I was very pleased to find this site.I want to thank you for this great content!! I enjoyed every little bit of it and I have you bookmarked to check out new stuff you post.
ReplyDeleteSelenium Training in Chennai
Selenium Training
iOS Training in Chennai
French Classes in Chennai
Big Data Training in Chennai
PHP Training in Chennai
PHP Course in Chennai
Great Applause. The content you shared is very inspirational. Thanks for Posting.
ReplyDeleteBlockchain certification
Blockchain course
Blockchain courses in Chennai
Blockchain Training Chennai
Blockchain Training in Anna Nagar
Blockchain Training in T Nagar
Blockchain Training in OMR
Blockchain Training in Porur
I joined to learn Web develpoment and got good understanding of the subject. Classes are interactive and teaching methodology is very good. Recommended for anyone who's looking for this course
ReplyDeletecloud computing training institutes in bangalore
cloud computing training in bangalore
best cloud computing training institutes in bangalore
cloud computing training course content
cloud computing training interview questions
cloud computing training & placement in bangalore
cloud computing training center in bangalore
very good to see this blog .this is really helpful
ReplyDeleteAngularJS Training in Chennai | AngularJS Training in Anna Nagar | AngularJS Training in OMR | AngularJS Training in Porur | AngularJS Training in Tambaram | AngularJS Training in Velachery
Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? share more details.
ReplyDeleteC and C++ Training Institute in chennai | C and C++ Training Institute in anna nagar | C and C++ Training Institute in omr | C and C++ Training Institute in porur | C and C++ Training Institute in tambaram | C and C++ Training Institute in velachery
A very good knowledge about salesforce.Quiet interesting.
ReplyDeleteJava training in Chennai
Java training in Bangalore
Java training in Hyderabad
Java Training in Coimbatore
Java Online Training
Outstanding blog post, I have marked your site so ideally I’ll see much more on this subject in the foreseeable future.
ReplyDeleteangular js training in chennai
angular js training in velachery
full stack training in chennai
full stack training in velachery
php training in chennai
php training in velachery
photoshop training in chennai
photoshop training in velachery
The content presented here is quite resembling the same. You have done a great job by sharing this in here.
ReplyDeletehadoop training in chennai
hadoop training in annanagar
salesforce training in chennai
salesforce training in annanagar
c and c plus plus course in chennai
c and c plus plus course in annanagar
machine learning training in chennai
machine learning training in annanagar
This is really too useful and have more ideas and keep sharing many techniques. Eagerly waiting for your new blog keep doing more.
ReplyDeletedata science training in chennai
data science training in omr
android training in chennai
android training in omr
devops training in chennai
devops training in omr
artificial intelligence training in chennai
artificial intelligence training in omr
This is extremely great information for these blog!! And Very good work. It is very interesting to learn from to easy understood. Thank you for giving information. Please let us know and more information get post to link.
ReplyDeleteAngular js Training in Chenai
Angular js Training in Velachery
Angular js Training in Tambaram
Angular js Training in Porur
Angular js Training in Omr
Angular js Training in Annanagar
The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this. amazon web services aws training in chennai
ReplyDeletemicrosoft azure training in chennai
workday training in chennai
android-training-in chennai
ios training in chennai
Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..Keep update more information..
ReplyDeleteIELTS Coaching in chennai
German Classes in Chennai
GRE Coaching Classes in Chennai
TOEFL Coaching in Chennai
Spoken english classes in chennai | Communication training
This blog is very useful for me it gives me the very knowledgeable information to me. Dreamsoft is the 20years old consultancy providing the experience certificate in many status of the India. the interested may contact at the 9599119376 or can visit our website for the
ReplyDeleteCareer Boosting Genuine Experience Certificate In Mumbai
https://experiencecertificates.com/experience-certificate-provider-in-mumbai.html
Career Boosting Genuine Experience Certificate In Gurugram
https://experiencecertificates.com/experience-certificate-provider-in-Gurgaon.html
Career Bosting Genuine Experience Certificate In Delhi
https://experiencecertificates.com/experience-certificate-provider-in-delhi.html
Career Boosting Experience Certificate In Noida
https://experiencecertificates.com/experience-certificate-provider-in-Noida.html
Career Boosting Genuine Experience Certificate In Bangalore
https://experiencecertificates.com/experience-certificate-provider-in-bangalore.html
Career Boosting Genuine Experience Certificate Hyderabad
https://experiencecertificates.com/experience-certificate-provider-in-Hyderabad.html