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
Orn IngvarOrn Ingvar 

After enabling Case feeds a CaseComment trigger throws a maximum trigger depth exceeded exception

Recently I enabled Case Feeds for the Service Cloud Console and after doing so I keep getting a maximum trigger depth exceeded for a CaseComment trigger I'm using to count the number of Case Comments on each case. The strange thing is that I only get this exception if I use the Internal Comments field on Cases and edit some other record at the same time.

 

Before I enabled Case Feeds this trigger ran fine without any problems under the same circumstance. I'm a little bit lost with this since I don't understand why the trigger depth should be exceeded only when I edit the case and create a comment at the same time.

 

Here is my code

 

	public void OnAfterInsert(CaseComment[] newCaseComments){
		for(CaseComment newCaseComment : newCaseComments)
		{
			//Get the parent Case Ids into a set
			caseIdSet.add( newCaseComment.ParentId );			
		}
		caseLst = [select Id from Case where Id in: caseIdSet];			
				
		AggregateResult cc_count = [select count(Id) total from CaseComment where ParentId in: caseLst];
		for(Case c: caseLst)
		{
			c.nmb_CaseCommentCount__c = (Integer)cc_count.get('total');			
		}		
		
			try
			{
				update caseLst;
			}
			catch( DmlException e)
			{
				Util_ExceptionObject.createErrorRecord('CaseCommentTriggerHandler', e.getMessage() ); 
			}
						
	}