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
narendra jagwannarendra jagwan 

plz give me a example to send email through trigger

Ramu_SFDCRamu_SFDC
The following posts might help

http://stackoverflow.com/questions/17860289/apex-beginner-email-from-a-trigger

Ajay_SFDCAjay_SFDC
Hi Narendra ,

You can do it in a following way :

for(Quote objQuote :trigger.new){
       
           if(objQuote .Status=='Accepted' && objQuote.ContactId !=Null)
            {
                 // Set parameters to Messagin.singleEmailMessage

                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                mail.setTemplateId(' '); // Give templateId here 
                mail.setTargetObjectId(objQuote.ContactId);  // Give necessary WhatId, Whoid. To Address , From Address as per your requirement
              //  mail.setWhatId(contactList[0].OpportunityId);        
                Messaging.sendEmail(new Messaging.Singleemailmessage[] {mail});
               
            }
}
Thanks ,
 Ajay
narendra jagwannarendra jagwan
hi ajay 
          i want . when we update contact filed  through trigger .. then send email after updation  so plz give me a example  contact 
Ajay_SFDCAjay_SFDC
Hi Narendra ,
Just replace the quote object in my example with contact .
If you want to check the changing value with the new one you need to use trigger.old .

Thanks ,
 Ajay
narendra jagwannarendra jagwan
hi ajay ..
                 thanks 
                                 i  have done  for this code..
   

 trigger Sendemail on Contact (after insert,after update) {


//String[] emails = new String [] {'j'};

    for (Contact  c: trigger.new) {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String emailAddress= [select email from contact where id=:c.id].email;
        mail.setTargetObjectId(c.id);
        String[] toAddresses = new String[] {emailAddress};
        mail.setToAddresses(toAddresses);
      //mail.setToAddresses(toAdd );
        mail.setSubject('contact');
        URL currentURL = URL.getCurrentRequestUrl();
        mail.setHtmlBody('view ur contact'+currentURL);
       
       
      //  emails.add(mail);
        Messaging.sendEmail(new Messaging.SingleEmailmessage[] { mail } );

    }

 


}