Skip to main content
Chris Manners ha fatto una domanda in #Apex
Hello,

I have a trigger that is hitting the SOQL query limit and I am not sure how to modify it. I believe I have to remove the SOQL query out of the FOR loop but I am not a developer so I am not sure how. Can someone help modify my code?

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18trigger trgTaskJudgementDateCannotBeBlank on Task (before update) {

Set<Id> ids = new Set<Id>();

  for(Task t:Trigger.New){

        if(t.Status=='Completed' && (t.Task_Reference__c =='L-739-5' || t.Task_Reference__c =='L-739-10')){

            ids.add(t.WhatId);

        }

    

    List<Trial__c> trialObj = [select Judgement_Date__c from Trial__c where id  IN: ids];

    

  for(Trial__c tr: trialObj){

    if(tr.Judgement_Date__c == NULL){

        t.addError('Please enter a judgement date for this trial record');

    }

    

  }

  }

}
2 risposte
  1. 31 gen 2022, 07:15
    Hi Christopher,

    You are writing a query inside the for loop because of which you are facing 101 SOQL issue. Can you copy paste the entire code so I can share you the updated one as some of the part of the code is missing.

    Thanks,

     
0/9000