[apex] Verify OperationWithLimitsInLoop for triggers

This commit is contained in:
Andreas Dangel 2024-09-06 18:42:22 +02:00
parent 9810bfc3cc
commit 97fe106724
No known key found for this signature in database
GPG Key ID: 93450DF2DF9A3FA3

View File

@ -519,4 +519,27 @@ public class Foo {
]]></code>
</test-code>
<!-- End system method invocations -->
<test-code>
<description>SOQL inside loop in trigger (#5138)</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>6</expected-linenumbers>
<code><![CDATA[
// from https://github.com/certinia/orizuru-sample-app/blob/master/src/apex/force-app/main/default/triggers/DataGeneratorStepTrigger.trigger
trigger DataGeneratorStepTrigger on DataGeneratorStep__e (after insert) {
List<GenerateDataTask__c> tasks = new List<GenerateDataTask__c>();
for (DataGeneratorStep__e event : Trigger.New) {
GenerateDataTask__c task = [SELECT Id, TaskStatus__c FROM GenerateDataTask__c WHERE Id=:event.SObjectId__c LIMIT 1];
if (task.TaskStatus__c != 'CREATED_ORDERS') {
task.TaskStatus__c = event.Status__c;
tasks.add(task);
}
}
update tasks;
}
]]></code>
</test-code>
</test-data>