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
kirubakaran viswanathankirubakaran viswanathan 

Best practises to skip the recursive trigger logic in batch job

I have 2 objects (Contact and SLM) both has their AFTER triggers. On each triggers we have that recursive trigger logic which we set the static variable at the end to avoid the recurssion.

I have a  batch class, which is updating the contact record and update the SLM records in a single transaction.  While doing that operation, I see the after update trigger for Contact object is working good and at the end it set the Static variable to true. When the SLM update happens, I am not seeing the SLM trigger is executing, may be because the static variable is set as true. 

I need this recursive check in both objects trigger because we have lot other Workflow and process builder to  update both object.
How to handle this? any thoughts. Thanks
Maurya PriyadarshiMaurya Priyadarshi
Try using checkRecursive.runOnce() in the code for trigger
Mubeen QawiMubeen Qawi
Came across a good trigger handler framework (check the github repo link, below), you may want to give it a shot as well. I know this doesn't address you immediate need, but will be resourceful for future development initiatives.

https://github.com/kevinohara80/sfdc-trigger-framework

Regards,
MQ
Nithesh NNithesh N
Not sure if it works, But You can try scheduling apex (for SLM) after contact batch apex. That may split the transaction I guess. 

Let me know your thoughts...your use case is pretty interesting..

Best,
Nithesh.