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
shoba shobashoba shoba 

Trigger to update the checkbox field

Hi
My scenario is to update the checkbox field if the Address field in Account is update. After 30 second of the record saved, it should uncheck the checkbox field.

Can anyone help me out to solve this issue.
Trigger throwing an error "
trigger test on Account (before update) {
list<Account> a =  new list<Account>();
Account acc = [select Id,checkboxForPopUp__c,BillingAddress,BillingCity,BillingCountry,BillingCountryCode,BillingPostalCode,BillingState,BillingStateCode,BillingStreet
                         from Account
                         where Id =:trigger.new];
if( (acc!=Null) &&
((acc.BillingAddress != trigger.oldmap.get(acc.id).BillingAddress) || (acc.BillingCity != trigger.oldmap.get(acc.id).BillingCity) ||
(acc.BillingCountry != trigger.oldmap.get(acc.id).BillingCountry) || (acc.BillingStateCode != trigger.oldmap.get(acc.id).BillingStateCode) ||
(acc.BillingStreet != trigger.oldmap.get(acc.id).BillingStreet))  
)
{
acc.checkboxForPopUp__c = TRUE;
a.add(acc);
}
update acc;
}

execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 001Q00000104rDvIAI; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 001Q00000104rDv) is currently in trigger test, therefore it cannot recursively update itself: []: Trigger.test: line 15, column 1"
Pun!5h3rPun!5h3r
Just remove update acc; (line  15 from above code snippet) and give a try
 
Pankaj_GanwaniPankaj_Ganwani
Hi Shoba,

Please refer below mentioned code:
 
trigger test on Account (before update) {
for(Account objAcc : trigger.new)
{
if((objAcc.BillingCity != trigger.oldmap.get(objAcc.id).BillingCity) || (objAcc.BillingCountry != trigger.oldmap.get(objAcc.id).BillingCountry) || (objAcc.BillingStateCode != trigger.oldmap.get(objAcc.id).BillingStateCode) || (objAcc.BillingStreet != trigger.oldmap.get(objAcc.id).BillingStreet))
{
	objAcc.checkboxForPopUp__c = TRUE; 
}
}

}

 
Adapala KullayappaAdapala Kullayappa
trigger testtrig on Account (before update) {
   List<Account> acc=new List<Account>();
   for(Account ac:trigger.new){
      Account oldOpp = Trigger.oldMap.get(ac.ID);
           if(ac.BillingAddress != oldopp.BillingAddress || ac.BillingCity != oldopp.BillingCity || ac.BillingCountry != oldopp.BillingCountry || ac.BillingPostalCode!= oldopp.BillingPostalCode || ac.BillingStreet != oldopp.BillingStreet){
               ac.checkboxForPopUp__c =true;
           }
       
   }
}


Before Update Don't Use the "Update" Try this Trigger So help full for You
shoba shobashoba shoba
Thank you for your replies. Can we uncheck the checkboxForPopUp__c after 30 second from record saved time.
Pankaj_GanwaniPankaj_Ganwani
I don't think there is way to reset the value of checkbox. To create a delay between both of these events, you can use future method containing logic for updating Accounts and call this from after insert event of the trigger.