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
anu_karthianu_karthi 

Too many SOQL queries: 21

hi,

 

in my application  object A have SFN Number of type input text field and object B have SFN Number which is looking over to objectA SFN Number.i am comparing the Object B SFN Number with ID of object A.At the time of saving the record the following error is raising

Too many SOQL queries: 21

trigger summation on chiranjeevi__Obj_A__c (before insert,before update) {
Double objBtotal = 0;
List<chiranjeevi__Obj_A__c> objAlist=new List<chiranjeevi__Obj_A__c>();
List<chiranjeevi__Obj_B__c> objBlist=new List<chiranjeevi__Obj_B__c>();

chiranjeevi__Obj_A__c[] id=[select ID from chiranjeevi__Obj_A__c];
for(chiranjeevi__Obj_A__c b : id)
{
objBlist=[SELECT chiranjeevi__Amount__c,chiranjeevi__SFN_Number__c FROM chiranjeevi__Obj_B__c Where chiranjeevi__SFN_Number__c =: b.id];
}
for (chiranjeevi__Obj_A__c objA : Trigger.new)
{
 for (chiranjeevi__Obj_B__c objB : objBlist)
 objBtotal += objB.chiranjeevi__Amount__c;
 {
  objA.chiranjeevi__Total_Amount__c=objBtotal; 
 
 }
}
}

If i check with particular id name it is working poperly.

 

If any one knows plz help me.

 

Thanks in advance,

Anu..

 

 

 

CloudDevCloudDev
Ok. All you need to do here is change id to a Set<> and load with ids from objA as per your code, then move the second SOQL statement out of the for loop use a single SOQL statement that uses an IN clause (i.e. in :id) to populate objList. You therefore have only 2 SOQL statements. Hope this helps...