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
phanip adminphanip admin 

Flow & Trigger are created on same object, how to avoid recursion.

Flow & Trigger are created on same object, how to avoid recursion. pleae explain this proivde the solution?
AshwiniAshwini (Salesforce Developers) 
Hi Phanip admin,

To avoid recursion, you can create a custom field on the object, like a checkbox or a text field which acts as a flag. When the Trigger executes, set this flag to a specific value or condition, and then use a decision element in your Flow to check this flag before taking any further action. If the flag is set, the Flow should exit without performing any updates.

You can also refer below links which can help you:
https://jayakrishnasfdc.wordpress.com/2020/02/23/recursive-trigger-in-salesforce/
https://www.saasguru.co/recursive-trigger-in-salesforce/#:~:text=Salesforce%20triggers%20are%20a%20fundamental,a%20phenomenon%20known%20as%20recursion.
https://www.apexhours.com/how-to-avoid-recursion-in-trigger/#:~:text=Recursion%20is%20the%20process%20of,Limit%20due%20to%20Recursive%20Trigger.

If this information helps, please mark the answer as best. Thank you
Nishant SoniNishant Soni
Hi,

You can use the following strategies to avoid recursion : 

1. Flow Variable: In the Flow, you can use a variable to store a unique identifier or flag (e.g., a timestamp) in a way that ensures it won't match the same identifier set by the Trigger.

2. Use a Static Variable: Create a static variable or a class-level variable in your Trigger handler class to keep track of whether the trigger should run or not. Set this variable in your Trigger and check it in your Flow to decide whether to perform certain actions.

3. Custom Field Flag: Create a custom checkbox field on the object (e.g., IsProcessed__c). In your Trigger, set this field to true after performing the necessary operations, and in your Flow, check this field before proceeding. Reset the flag to false when appropriate.

Thanks,
Nishant