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
Siana DcruzSiana Dcruz 

How to avoid recursion in trigger

Hey all,
I have a trigger something like this:

trigger ClaimData on Intake__c (after update) {

 Profile p = [ SELECT Name FROM Profile WHERE Id =: UserInfo.getProfileId() ];
if (p.Name != 'Data Manager') {
        List<Claim__c> claims = new List<Claim__c>();
        List<Id> intakeIds = new List<Id>();
        List<Claim__c> claimsToUpdate = new List<Claim__c>();
        for (Intake__c i :{
        claims = [SELECT fld1,fld2,fld3....,fldn from claim__c where intake__c IN: intakeIds];
        List<recordType> recordTypes = [select id,name from recordType where SobjectType ='claim__c' And name in ('WC','AL','PROP','GL','MR')];     
        Map<String,recordType> mapRecordTypes = new Map<String,recordType>();
        Map<Id, List<Claim__c>> claimMap= new Map<Id, List<Claim__c>>();
        for (recordType r: recordTypes) {
            mapRecordTypes.put(r.DeveloperName, r);
        for (Claim__c c: claims) {
            List<Claim__c> int2Clms = claimMap.get(c.intake__c);
            if(int2Clms == null){
                claimMap.put(c.intake__c,int2Clms = new List<Claim__c>());
        for(Intake__c i :{
   List<Claim__c > claimsList = claimMap.get(i.Id);
                 for(Claim__c c:claimsList){

Since this is an after update trigger and I am updating records with an external dml,it might lead to recurssion.Can anyone
please tell me how to avoid recursion in my trigger.Any help would be greatly appreciated.
Hi Siana

kinldy refere this you will get some idea to process further.

Hope it will help you....

karthikeyan perumalkarthikeyan perumal

There are some ways you can avoid Recursive 
Using Trigger Context Variable in your Trigger. 
Before Update or Insert. Make sure your are using Trigger Context Variable. like Trigger.isInsert,Trigger.isupdate according to you consition, 
also you can use Static Boolean or Static variable to mark sure you trigger run once. 
Here is the Example.

Hope it will Help you.