Fix DML inside a loop
Every insert, update or delete statement counts against the limit of 150 per transaction.
Your task
Fix the handler so it saves all follow-up Tasks with one insert, however many Opportunities were created.
public class AS_37B5DFEF8A27_FollowUpTasks {
public static void afterInsert(List<Opportunity> opportunities) {
for (Opportunity opportunity : opportunities) {
Task followUp = new Task(
Subject = 'Follow up: ' + opportunity.Name,
WhatId = opportunity.Id
);
insert followUp;
}
}
}Requirements
- createsOneLinkedTask should pass
- createsATaskPerOpportunity should pass
- usesOneDmlStatementForTheTasks should pass
- handlesTwoHundredOpportunities should pass