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
Asad WaliAsad Wali 

compare trigger.old and trigger.new on after update. If i change/update address from lead then my trigger call and update my custom fileds in that lead.

ANUTEJANUTEJ (Salesforce Developers) 
Hi Asad,

Can you elaborate the scenario and if possible please provide an example to check further also could you mention where you are facing the issue while implementing this scenario`
Asad WaliAsad Wali

Thanks for Reply @ANUTEJ

I am doing a task in which i write trigger on after insert on the base of address.

When i enter address in lead it fecth data from api and check if the address is same in API and Lead then it insert apn value in my lead.

Now i want to update address in same lead and when i update address in lead it will update apn against this address.

 

Asad WaliAsad Wali
trigger TriggerOnLead on Lead (before insert, after insert, after delete, before update, after update) {

    if (Trigger.isInsert) {
        if (Trigger.isBefore) {
            // Process before insert
             
        } else if (Trigger.isAfter) {
            // Process after insert
            List<ID> recordIds = new List<ID>();
         //   List<ID> oldrecordIds = new List<ID>();
            // add Id in recordsIds
            for(Lead Leads:trigger.new){                 // it will get all data/field which is available in leads
        
                recordIds.add(Leads.ID);               
            }
            TriggerOnLeadHandler.makeGetCallout(recordIds);
        }        
    }
    else if (Trigger.isDelete) {
        // Process after delete
    }

This is my trigger on after insert.
Michael MMichael M
We are using a similar logic in our org. Here was the line that we used:

if (trigger.isupdate && Trigger.oldMap.get(l.id).status != 'Pending Admit' && l.status == 'Pending Admit'){
//logic and other updates here....
}
Asad WaliAsad Wali

Hey Micheal

 

i use similar to your

but i face error on future method.

Update failed. First exception on row 0 with id 00Q2x00000CZm0tEAD; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, TriggerOnLead: execution of AfterUpdate

This is error when i update lead, i get this error.