To avoid these kind of situation we can use public class static variable.
In StopRecursive class, we have a static variable which is set to true by default.
public class StopRecursive {
public static Boolean isFirstTime = true;
}
trigger SampleTrigger on Contact (after update){
Set<String> accIdSet = new Set<String>();
if(StopRecursive .isFirstTime){
StopRecursive .isFirstTime = false;
for(Contact conObj : Trigger.New){
if(conObj.name != ‘SFDC’){
accIdSet.add(conObj.accountId);
}
}
// Use accIdSet in some way
}
}
Once this trigger fired the static variable value will set to false and trigger will not fire again.
Hope this helps!