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
MarrisMarris 

Trigger on Account can't run the condition on Lead Conversion

Hi

 

Lead Converted to Account/Contact

 

On checking the "Enforce Validation and Triggers from Lead Convert" checbox on Lead-->Setting It will run my [Account After update,After Insert] trigger on Lead Conversion. But While Converting Lead if we create a new Account for that lead then Insert trigger on Account will sent out a notification mail.
If we assign the lead to the existing Account then Update trigger on Account is called, there we are checking for[ Old value vs new value for Account owner] on every update.In this case the old and new owner is same So trigger failed.Can Anybody help on this issue

 

Thanks

Marris

RoyGiladRoyGilad

Hi Marris,
Can you please provide error you are experiencing?

Also is your code is something like (in the after update trigger):
For (Account a: trigger.new)
{

 Account oldRecord = trigger.oldMap.get(a.ID)

if (a.ownerId!=oldRecord.OwnerId)

{

......

}

}

?

MarrisMarris

Hi Roy

 

It is not erroring out. As the old and new value in trigger are same it goes out without sending a notification mail

 if(Trigger.isupdate){
        system.debug('Old Owner:'+trigger.old[i].ownerId);
        system.debug('New Owner:'+trigger.new[i].ownerId);
            if((trigger.old[i].ownerId != trigger.new[i].ownerId)&&(trigger.new[i].ownerId != Null)){
                   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                   //mail.setTargetObjectId(trigger.new[i].ownerId);
                   mail.setTargetObjectId(con.id);
                   mail.setwhatid(trigger.new[i].Id);
                   System.debug('Email Id:'+u.Email);
                   mail.toAddresses = new String[] { u.Email };
                   System.debug('RecordType:'+trigger.new[i].recordtypeid);
                   System.debug('RecordTypeold:'+a.Recordtype.Name);
                  if((a.recordtype.Name == 'End User')&&(trigger.new[i].ownerid != Null)){
                   
                       System.debug('I am in End User');
                       EmailTemplate template1 = [ SELECT Id FROM EmailTemplate WHERE DeveloperName = 'Send_Notification_on_update_of_Account_Owner'];
                       mail.setTemplateId(template1.Id);
                  
                   }else {
                       System.debug('I am in Portal User');
                       EmailTemplate template1 = [ SELECT Id FROM EmailTemplate WHERE DeveloperName = 'Send_Notification_on_update_of_Account_Owner_for_Partner'];
                       mail.setTemplateId(template1.Id);
                   
                   }
               mail.setOrgWideEmailAddressId(listOWEA[0].Id);       
               mail.setBccSender(false);
               mail.setUseSignature(false);
               mail.setSaveAsActivity(false);
               Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

            }

 Thanks

Marris