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
seshu.babu1.3923612903234636E12seshu.babu1.3923612903234636E12 

email functionality

I want to send an email when the record is created.Example when the data comes from the informatica (ETL) to salesforce, another object record will be created and after the it will send the email.
The mails might be bulk emails or individual emails (morethan 400) with attachment.

Any body have any idea how to write code. Please help
Jayson Faderanga 14Jayson Faderanga 14
Hope the below trigger can guide you sending email alerts, this code is bulkified and will send email to leads that uses the Rating field as reference.

trigger emailLeads on Lead (after update) {

List<Messaging.SingleEmailMessage> mails =  new List<Messaging.SingleEmailMessage>();
List<Lead> allLeads = new List<Lead>();

for (Lead exLead : Trigger.new) {


Lead OldexLead = Trigger.oldMap.get(exLead.Rating);

Boolean OldexLeadnotRating = OldexLead.Rating.equals('Cold');
Boolean OldexLeadRating    = exLead.Rating.equals('Cold'); 

if(!OldexLeadnotRating && OldexLeadRating) {

allLeads.add(exLead);
system.debug(allLeads);

           }

for (Lead leadslist : allLeads) {

if (leadslist.email != null) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

List<String> sendTo = new List<String>();

sendTo.add (leadslist.Email);
mail.setToAddresses(sendTo);

mail.setReplyTo('jfaderanga@salesforce.com');
mail.setSenderDisplayName('The Pips Company');
mail.setSubject('Urgent Business Proposal');

String body = 'Dear ' + leadslist.FirstName +' ,' + '<br / ><br />' ;

body += 'I would like to say thanks to everybody that has been part of my lead';
body += 'I was so amaze about the story of life you all have shared to me';
body += 'I am hoping we meet again someday, cause its been a day since we first began the journey' + '<br /> <br />';

mail.setHtmlBody(body);

mails.add(mail);

        }
        
 Messaging.sendEmail(mails);
 
 } 

    }