am getting the following error:

CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Effectivefilingdate: maximum trigger depth exceeded Patent trigger event AfterUpdate

below is my code-what is the change i want to do...

trigger Effectivefilingdate on Patent__c (after insert,after update) {
if(trigger.isinsert || trigger.isupdate)
    List<Patent__c> objPatsToUpdate = NEW List<Patent__c>();
    Set<Id> PatIds = new Set<Id>();
    for (Patent__c Pat : Trigger.new){
    for (Patent__c objPatent : [select Id,Effective_Filing_Date__c,Application_Date__c,Priority_Dates__c from Patent__c where Id IN:PatIds]) 
        //Patent__c oldpat = Trigger.oldMap.get(objPatent.Id);

        if (objPatent.Priority_Dates__c == Null)
            objPatent.Effective_Filing_Date__c = objPatent.Application_Date__c;
        if (objPatent.Priority_Dates__c !=null)
            List<date> lstDtPrioirtyDates = New List<date>();
            List<date> lstDtPrioirtyDates1 = New List<date>();
            List<String> lstStrPriorityDates = objPatent.Priority_Dates__c.replaceAll( '\\s+', '').split(',');
            date mydate;
            for(string st : lstStrPriorityDates)
                date dt = date.valueof(st);
                if(mydate == null)
                    mydate = dt;
                if(mydate > dt)
            objPatent.Effective_Filing_Date__c = mydate;
            system.debug('Small date'+mydate);
    update objPatsToUpdate;

1 Answer 1


Your trigger is recursing because, in an after update trigger, you perform a DML update on the same objects received by the trigger without altering the fields that cause your trigger to process those objects.

You make changes to Patent__c objects under two conditions, both based on Priority_Dates__c. However, your code doesn't change Priority_Dates__c when it performs an update. This ensures that your after update trigger, when it runs during the new update DML you fire, will process those same records again, and update them again, until you hit the stack depth limit.

It appears to me that your trigger could be run before insert and before update rather than after, when you can directly make changes to the objects in Trigger.New rather than querying and firing another DML update. This would prevent recursion without having to implement a more complex recursion-prevention architecture.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .