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"

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;
}
}

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);
}
}

Create a Contact record and fill the Email field with your email and save it.
You will receive an email from the your salesforce.

Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. 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..

    rpa training in electronic-city | rpa training in btm | rpa training in marathahalli | rpa training in pune

    ReplyDelete
  3. 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!
    Python training in marathahalli | Python training institute in pune

    ReplyDelete
  4. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    java training in jayanagar | java training in electronic city

    java training in chennai | java training in USA

    ReplyDelete
  5. Nice post. I learned some new information. Thanks for sharing.

    Guest posting sites
    Technology

    ReplyDelete
  6. your blog information's are really creative and It contains full of new innovative ideas.
    thank 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

    ReplyDelete
  7. 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.


    Selenium 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

    ReplyDelete
  8. 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.
    Angular 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

    ReplyDelete
  9. 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

    microsoft azure training in chennai

    workday training in chennai

    android-training-in chennai

    ios training in chennai

    ReplyDelete
  10. 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..
    IELTS Coaching in chennai

    German Classes in Chennai

    GRE Coaching Classes in Chennai

    TOEFL Coaching in Chennai

    Spoken english classes in chennai | Communication training

    ReplyDelete
  11. 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
    Career 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

    ReplyDelete

Post a Comment

Popular posts from this blog

Test-Driven Development in Salesforce

Setting a default 'From' address when sending an email from Cases