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
KyoKyo 

System Limit 101

System.LimitException: Too many SOQL queries: 101 

 

Trigger.UpdateQLine: line 4, column 44

 

 

trigger UpdateQLine on Quotes_Line_Item__c (after update) {
    for(Quotes_Line_Item__c QL:trigger.new){
    if(QL.isClosed__c == false){
        Opportunities_Line_Item__c[] OPL = [Select Id ,UP1__c,Quantity__c from Opportunities_Line_Item__c Where Id =: QL.Opportunities_Line_Item__c Limit 1000];
        for(Opportunities_Line_Item__c OL:OPL){
        OL.Quantity__c = QL.Quantity__c;
        OL.UP1__c = QL.Unit_Price_For__c;
        }
        update OPL;
        }
    }
}

 

 

bob_buzzardbob_buzzard

The problem here is that you have nested a select statement inside the loop that is iterating the trigger.new records.

 

The trigger needs "bukifying" so that you only have a single soql query that pulls back all the affected records in one go.

 

Usually you'd have something similar to the following for this:

 

 

  List<Id> oliIds=new List<Id>();
  for(Quotes_Line_Item__c QL:trigger.new){
    oliIds.add(QL.Opportunities_Line_Item__c);
  }
 
  Opportunities_Line_Item__c[] OPL = [Select Id ,UP1__c,Quantity__c from Opportunities_Line_Item__c Where Id IN: oliIds];

 

Depending on your code, you may need to put these into a Map so that you can retrieve them by Id.

 

KyoKyo

 

Thank you Bob. but it's not complate.
System.LimitException: Too many SOQL queries: 101 
I'm Create OppLine 55 record and QuotesLine 55 record = 110 record. but system limit 100
I can add system limit more 100 ?
Thank you so much.

 

bob_buzzardbob_buzzard

You won't be able to change the limit, as this is a hard governor limit.

 

If you've moved the SOQL outside of the loop, its probably the update (which I didn't notice first time through).  Rather than updating each record, store them in a list and update them in one go outside of the loop.

maiyakumaiyaku

Thank you Bob.

Perfect!