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

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

The below link explains more about this

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

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

trigger SendEmailOnOwnerChange on Account (after update) {
    if (trigger.old[0].OwnerId !=[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 =[0].OwnerId].Name;

        String[] toAddresses = new String[] {emailAddr};

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

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

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