Stop a trigger calling itself
maximum trigger depth exceeded means a trigger caused DML that ran the same trigger, sixteen times.
Your task
Fix the handler so each Case closed in a transaction is marked exactly once, and the follow-up update does not run the handler's work again.
public class AS_AFE55B6263D0_CaseCloser {
public static void afterUpdate(List<Case> cases, Map<Id, Case> oldMap) {
List<Case> followUps = new List<Case>();
for (Case caseRecord : cases) {
if (caseRecord.Status == 'Closed') {
followUps.add(new Case(
Id = caseRecord.Id,
Description = 'Closed by the handler'
));
}
}
if (!followUps.isEmpty()) {
update followUps;
}
}
}Requirements
- marksAClosedCaseOnce should pass
- leavesAnOpenCaseAlone should pass
- marksTwoCasesClosedSeparately should pass
- handlesTwoHundredClosedCases should pass