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
sultansultan 

How to send an emails to the users by using a Trigger?please send the code anybody?

Ramu_SFDCRamu_SFDC
The below link explains more about this


http://www.sfdc99.com/2014/03/01/sending-emails-using-apex/

Once again you can find the information on almost all the features of salesforce in the above blog
Abi DuthuAbi Duthu
Hi,

Use the method Messaging.SingleEmailMessage. Refer the below given code. 

trigger SendEmailOnOwnerChange on Account (after update) {
    if (trigger.old[0].OwnerId != trigger.new[0].OwnerId) {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

        String emailAddr = [select Email from User where Id = :trigger.old[0].OwnerId].Email;
        String newOwnerName = [select Name from User where Id = :trigger.new[0].OwnerId].Name;

        String[] toAddresses = new String[] {emailAddr};
        mail.setToAddresses(toAddresses);

        mail.setSubject('Owner Changed for Account : ' + trigger.new[0].Name);

        mail.setPlainTextBody('Owner of Account: ' + trigger.new[0].Name + ' Changed to ' + newOwnerName);
        mail.setHtmlBody('Owner of Account: <b>' + trigger.new[0].Name + '</b> Changed to <b>' + newOwnerName  + '</b>');

        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
}