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
ram dram d 

Need Help in Writing After Update Trigger

Hi All ,I have requirement if any one helps i am very thankful to them please see my requirement below
I have 3 objetcs like Account,Account Convace,Catlog Account is lookup of Account convace and Catlog is Master object for Account Convas so when the user changes the Account name in Account convas then we need to send a email for  all the users in the Account convas with Account old name and new name please any one help in this Requirement 
Raja ReddyRaja Reddy
Hope this helps yyou
trigger SendEmailOnOwnerChange on Lead (before update,After Update) {
    if (trigger.old[0].OwnerId !=[0].OwnerId ) {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

        //Select the Email Address of the old owner
        String emailAddrnew = [select Email from User where Id = :trigger.old[0].OwnerId].Email;
        String emailAddrold = [select Email from User where Id =[0].OwnerId].Email;
        //Select the new owner and old owner from user
        String newOwnerName = [select Name from User where Id =[0].OwnerId].Name;
        String oldownerName=[select name from User where Id =:trigger.old[0].OwnerId].Name;
        //Store the email address
        String[] emailAddrnew1 = new String[] {emailAddrnew};
        String[] emailAddrold1 = new string[]{emailAddrold};
        mail.setToAddresses(emailAddrnew1 );
        mail.setCcAddresses(emailAddrold1 );

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

        mail.setPlainTextBody('Owner of lead: ' + oldownerName + ' Changed to ' + newOwnerName);
        mail.setHtmlBody('This is to notify that the Owner of lead: <b>' +[0].Id+'<b>&nbsp;&nbsp;Changed from</b>&nbsp;&nbsp;'+oldownerName  + '</b>&nbsp;&nbsp; Changed to <b>' + newOwnerName  + '</b>');

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