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
NalinakuNalinaku 

After Update Trigger on Account is not Working

I have a problem with Account trigger afterupdate event. Below are the problem details. 

Expectation is: Whenever I update a Status column in Account, there is a method in AfterInsertUpdate in trigger which updates the status of custom objects related to Account(child objects)

Problem is : Whenever I update the Status column in Account, trigger fires and executes upto BeforeUpdate event and executes all the methods which are being called in Beforeupdate event. But after this I see in Debug log that some validation fires and after that again BeforeUpdate event starts and I see that oldmap no longer hold the status to which I updated the Account. i.e. oldmap and new values are same, which results in my condition in IF statement not meeting and hence update is not happening. 

Actions Taken: 
1. 
I commented the all the methods step by step being called in Before update and checked the logs but no luck. 
2. I Inactivated all update workflows related to Account and checked but no luck again

Thanks in Advance for your help. 

Trigger:
trigger IS_AccountTrigger on Account (after insert, after update, before insert, before update, before delete, after delete) {
    system.debug('reached insisde trigger');
    ISecG_Trigger_Settings__c objTriggerSetting = ISecG_Trigger_Settings__c.getInstance();
   
    
   if(objTriggerSetting.Enable_Account_Trigger__c) {
        if(Trigger.isAfter && (Trigger.isInsert || Trigger.isUpdate)) {
            system.debug('reached inside after trigger');
            IS_AccountTriggerHandler.afterInsertUpdate();     \\MY METHOD IS BEING CALLED FROM HERE
             if(trigger.isInsert){             
            <CustomClass.CustomMethod>(Trigger.new,Trigger.oldmap); 
             }
        }
        if(Trigger.isBefore && (Trigger.isInsert || Trigger.isUpdate)) {
            system.debug('reached insisde before trigger@@@@@');
            IS_AccountTriggerHandler.beforeInsertUpdate();
         }
        if(trigger.isInsert && trigger.isBefore) {
            IS_AccountTriggerHandler.beforeInsert();
        }
        if(trigger.isBefore && trigger.isUpdate) {
            IS_AccountTriggerHandler.beforeUpdate();
         }
        if(Trigger.isBefore && Trigger.isDelete) {
            IS_AccountTriggerHandler.beforeDelete();
            <CustomClass.CustomMethod>(Trigger.old); 
      }
        if(Trigger.isAfter && Trigger.isDelete) {
            IS_AccountTriggerHandler.afterDelete(Trigger.old);
           }
        }
   }
Amit Chaudhary 8Amit Chaudhary 8
Can you please share the debug log for validation rule ? Look like you are getting some exception in before update due to that after update is  not executing
NalinakuNalinaku
Hi Amit, 
Thanks for your response on this. I checked the every validation rule and I see its passed.  Below is the extract from debug log. ( i have removed some parts of validation rule log only which holds the client data). 
Below log start from the end of Before update trigger event and ends with the start of the Before update again as stated before.
 
07:26:17.689 (689794999)|CUMULATIVE_LIMIT_USAGE_END

07:26:17.45 (691765184)|CODE_UNIT_FINISHED|IS_AccountTrigger on Account trigger event BeforeUpdate|__sfdc_trigger/IS_AccountTrigger
07:26:17.715 (715659488)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:Account:001o000000qHBng
07:26:17.715 (715683141)|VALIDATION_RULE|03do0000000FbzI|Address_Street_Validation_End_Customer
07:26:17.715 (724245182)|VALIDATION_FORMULA|


07:26:17.715 (724270986)|VALIDATION_PASS
07:26:17.715 (724273971)|VALIDATION_RULE|03do0000000FbzJ|Address_Street_Validation_Partner
07:26:17.715 (725146068)|VALIDATION_FORMULA|AND 

07:26:17.715 (725168678)|VALIDATION_PASS
07:26:17.715 (725171002)|VALIDATION_RULE|03d1J000000fxc1|CustomPCT_segment
07:26:17.715 (728807946)|VALIDATION_FORMULA|AND(

07:26:17.715 (728821563)|VALIDATION_PASS
07:26:17.715 (728824204)|VALIDATION_RULE|03do0000000RgrN|PostalCode_Required_for_selected_Country
07:26:17.715 (729255530)|VALIDATION_FORMULA|AND(

07:26:17.715 (729278474)|VALIDATION_PASS
07:26:17.715 (729280905)|VALIDATION_RULE|03do0000000RgrO|Registration_Status
07:26:17.715 (729476392)|VALIDATION_FORMULA|AND(

07:26:17.715 (729488071)|VALIDATION_PASS
07:26:17.715 (729490121)|VALIDATION_RULE|03do0000000RgrP|State_Required_for_selected_Country
07:26:17.715 (729875759)|VALIDATION_FORMULA|AND( 

07:26:17.715 (729894941)|VALIDATION_PASS
07:26:17.715 (729897365)|VALIDATION_RULE|03do0000000RgrI|Address_Required_for_Accounts
07:26:17.715 (730320795)|VALIDATION_FORMULA|AND(

07:26:17.715 (730339291)|VALIDATION_PASS
07:26:17.715 (730341542)|VALIDATION_RULE|03d1J000000fxUv|Lock_Account_Fields_End_Customer
07:26:17.715 (730812092)|VALIDATION_FORMULA|AND ( 

07:26:17.715 (730830262)|VALIDATION_PASS
07:26:17.715 (730832547)|VALIDATION_RULE|03do0000000RgrL|Lock_Account_Name_End_Customer
07:26:17.715 (731050256)|VALIDATION_FORMULA|AND (

07:26:17.715 (731537966)|VALIDATION_PASS
07:26:17.715 (731540291)|VALIDATION_RULE|03do0000000Bd2Y|Validation_On_Site_Partner_Type
07:26:17.715 (731694035)|VALIDATION_FORMULA|

07:26:17.715 (731702966)|VALIDATION_PASS
07:26:17.715 (731704824)|VALIDATION_RULE|03d1J000000SFIs|Website_Length_100
07:26:17.715 (731758100)|VALIDATION_FORMULA|

07:26:17.715 (731764683)|VALIDATION_PASS
07:26:17.715 (731959691)|CODE_UNIT_FINISHED|Validation:Account:001o000000qHBng
07:26:17.732 (732666225)|CODE_UNIT_STARTED|[EXTERNAL]|DuplicateDetector
07:26:17.732 (732687966)|DUPLICATE_DETECTION_BEGIN
07:26:17.732 (733753449)|DUPLICATE_DETECTION_RULE_INVOCATION|DuplicateRuleId:0Bmo0000000PdzB|DuplicateRuleName:IS Account Matching Rule 1|DmlType:UPDATE
07:26:17.732 (744841941)|DUPLICATE_DETECTION_RULE_INVOCATION|DuplicateRuleId:0Bmo0000000PdzG|DuplicateRuleName:IS Account Matching Rule 2|DmlType:UPDATE
07:26:17.732 (744938921)|DUPLICATE_DETECTION_RULE_INVOCATION|DuplicateRuleId:0Bmo0000000PdzL|DuplicateRuleName:IS Account Matching Rule 3|DmlType:UPDATE
07:26:17.732 (745010122)|DUPLICATE_DETECTION_RULE_INVOCATION|DuplicateRuleId:0Bmo0000000PdzQ|DuplicateRuleName:IS Account Matching Rule 4|DmlType:UPDATE
07:26:17.732 (745073062)|DUPLICATE_DETECTION_RULE_INVOCATION|DuplicateRuleId:0Bmo0000000PdzV|DuplicateRuleName:IS Account Matching Rule 5|DmlType:UPDATE
07:26:17.732 (745172388)|DUPLICATE_DETECTION_END
07:26:17.732 (745180168)|CODE_UNIT_FINISHED|DuplicateDetector
07:26:18.84 (1084929927)|CODE_UNIT_STARTED|[EXTERNAL]|TerritoryRealign
07:26:18.84 (1102001380)|CODE_UNIT_FINISHED|TerritoryRealign
07:26:18.114 (1114587916)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
07:26:18.114 (1114633109)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
07:26:18.114 (1114681583)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4
07:26:18.114 (1114693360)|VARIABLE_SCOPE_BEGIN|[1]|this|pi.LogAccountChange|true|false
07:26:18.114 (1114752114)|VARIABLE_ASSIGNMENT|[1]|this|{}|0x2318d68f
07:26:18.115 (1115594970)|CUMULATIVE_LIMIT_USAGE
07:26:18.115 (1115594970)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 1 out of 100
  Number of query rows: 1 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 312 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

07:26:18.115 (1115594970)|LIMIT_USAGE_FOR_NS|rvpe|
  Number of SOQL queries: 1 out of 100
  Number of query rows: 1 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

07:26:18.115 (1115594970)|CUMULATIVE_LIMIT_USAGE_END

07:26:18.118 (1118276331)|ENTERING_MANAGED_PKG|rvpe
07:26:18.118 (1118369957)|ENTERING_MANAGED_PKG|rvpe
07:26:18.118 (1118758923)|ENTERING_MANAGED_PKG|rvpe
07:26:18.118 (1118801005)|ENTERING_MANAGED_PKG|rvpe
07:26:18.118 (1118898360)|ENTERING_MANAGED_PKG|rvpe
07:26:18.118 (1118918593)|ENTERING_MANAGED_PKG|rvpe
07:26:18.118 (1118941803)|ENTERING_MANAGED_PKG|rvpe
07:26:18.118 (1119016968)|ENTERING_MANAGED_PKG|rvpe
07:26:18.118 (1119069712)|ENTERING_MANAGED_PKG|rvpe
07:26:18.118 (1119139099)|ENTERING_MANAGED_PKG|rvpe
07:26:18.118 (1120933528)|ENTERING_MANAGED_PKG|rvpe
  .
  . <After 100s of ENTERING_MANAGED_PKG>
  .
07:26:18.118 (1403900322)|ENTERING_MANAGED_PKG|rvpe
07:26:18.118 (1403914277)|ENTERING_MANAGED_PKG|rvpe
07:26:18.118 (1403996838)|DML_BEGIN|[32]|Op:Update|Type:Account|Rows:1
07:26:18.414 (1414639335)|CUMULATIVE_LIMIT_USAGE
07:26:18.414 (1414639335)|LIMIT_USAGE_FOR_NS|(default)|
  
  
  Number of SOQL queries: 1 out of 100
  Number of query rows: 1 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 456 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

07:26:18.414 (1414639335)|LIMIT_USAGE_FOR_NS|rvpe|
  Number of SOQL queries: 4 out of 100
  Number of query rows: 9 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 1 out of 150
  Number of DML rows: 1 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

07:26:18.414 (1414639335)|CUMULATIVE_LIMIT_USAGE_END

07:26:18.118 (1416175221)|ENTERING_MANAGED_PKG|rvpe
07:26:18.118 (1416248043)|ENTERING_MANAGED_PKG|rvpe
07:26:18.118 (1416274054)|ENTERING_MANAGED_PKG|rvpe
07:26:18.118 (1416309211)|ENTERING_MANAGED_PKG|rvpe
07:26:18.118 (1416398633)|ENTERING_MANAGED_PKG|rvpe
07:26:18.118 (1416414158)|ENTERING_MANAGED_PKG|rvpe
07:26:18.118 (1416436363)|ENTERING_MANAGED_PKG|rvpe
07:26:18.118 (1416510527)|ENTERING_MANAGED_PKG|rvpe
07:26:18.118 (1416548709)|ENTERING_MANAGED_PKG|rvpe
07:26:18.118 (1416568839)|ENTERING_MANAGED_PKG|rvpe
07:26:18.416 (1416605257)|CUMULATIVE_LIMIT_USAGE
07:26:18.416 (1416605257)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 1 out of 100
  Number of query rows: 1 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 456 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

07:26:18.416 (1416605257)|LIMIT_USAGE_FOR_NS|rvpe|
  Number of SOQL queries: 4 out of 100
  Number of query rows: 9 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 1 out of 150
  Number of DML rows: 1 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

07:26:18.416 (1416605257)|CUMULATIVE_LIMIT_USAGE_END

07:26:18.418 (1418047265)|CODE_UNIT_STARTED|[EXTERNAL]|01qo0000000xVM9|IS_AccountTrigger on Account trigger event BeforeUpdate|__sfdc_trigger/IS_AccountTrigger
07:26:18.418 (1418075516)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
07:26:18.418 (1418082301)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
07:26:18.418 (1418104563)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
07:26:18.418 (1418112472)|VARIABLE_SCOPE_BEGIN|[16]|this|IS_AccountTrigger|true|false

 
Paul S.Paul S.
This sounds like an order of execution issue.  I'd assume that if it were validation related, you'd error out at some point.  What are the values you're expecting for old and new at the various steps through your trigger?  I'm not sure I follow what you're saying when you mention "I see that oldmap no longer hold the status to which I updated the Account."  It sounds like you're expecting oldMap to contain the updated value of the account status?
NalinakuNalinaku
Hi Pauls, 
The oldmap holds the Old value of status correct untill actual update i.e. it holds the old value in all the before trigger context.
For ex; oldmap = {Status = 'Registered'}
             newmap = {Status = 'Inactive'}
This is correct untill the actual update happens. But after Update old and new values looks like below. 
            oldmap = {Status = 'Inactive'}
             newmap = {Status = 'Inactive'}
I have my logic in the after update which compares these 2 values and then does the job. but since old and new is same its not doing my job. 


Even workflows are disabled, even then I noticed this behaviour. 
Paul S.Paul S.
Are either of the handler methods that are being called in a before update context - beforeInsertUpdate or beforeUpdate - updating the status? How about any process builder processes?
NalinakuNalinaku
@pauls
None of them are updating status. And process builders criteria is not matching with this case. 
 
Jwdv22Jwdv22

@Nalinaki 

Did you ever solve your issue? I'm having the same problem.

NalinakuNalinaku
@Jwdy, Please check if you have any managed package retriggering the trigger. In my case MP was the culprit.