+ Start a Discussion
StaciStaci 

case comment trigger

I have the following trigger to produce a canned response case comment when a option is picked from a picklist.  It works BUT if someone actually puts a case comment on a case after the picklist has been used, it errors:

Error:Apex trigger CW_DSS_CaseTrigger caused an unexpected exception, contact your administrator: CW_DSS_CaseTrigger: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CW_DSS_CaseTrigger: maximum trigger depth exceeded Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate Case trigger event AfterUpdate: []: Trigger.CW_DSS_CaseTrigger: line 25, column 1


What is causing this?

 
trigger CW_DSS_CaseTrigger on Case (after update) {
    

   List<caseComment> caseCommentList = new List<caseComment>();
    for (Case c: Trigger.new)
    {
        
        caseComment cc = new caseComment();
        if(c.Macros__c == 'Application Support information'){
                cc.parentid = c.ID;
                cc.commentbody = 'For application (DSSi and Relay Server) support and troubleshooting requests, please provide the following information.'+'\n' +
                                    'Minimum DSS Ticket Information requirements:'+'\n' +
                                    'Site Name:' +'\n' +
                                    'Site Contact: (For possible Site IT related issues)' +'\n' +
                                    'DSSi Software Version:' +'\n' +
                                    'Problem/Inquiry:' +'\n' +
                                    'Troubleshooting Steps Taken:' +'\n' +
                                    'This information is required with all DSS support requests. Failure to provide this requested information may delay your request.';
                cc.ispublished = true;
                casecommentlist.add(cc);
               
        }

    }
            insert caseCommentList;
            
}

 
Best Answer chosen by Staci
RituSharmaRituSharma
It seems that trigger is stuck in the loop i.e. something is refiring the trigger again and again. Use a static variable to avoid reccursion.