+ Start a Discussion

Too many SOQL queries: 21



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;

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


If any one knows plz help me.


Thanks in advance,





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...