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
Nano RandyNano Randy 

Error

Hi,
I have a trigger. when I'm trying to update data through dataloader, I getting Soql 101 query limit error
trigger Approvers on Approval__c (before insert,before update)
{
Boolean assigned ;
list<Approver__c> lstApprover;
for(Approval__c c:trigger.new)
{
 if(c.Category__c=='Dental' || c.Category__c=='General')
 {
 lstApprover = [Select Bill__c, Approver_1__c, Approver_2__c,Category__c,Market__c,Reason__c, Id, RecordTypeId, Region__c, Division__c, Sub_Division__c,Zone__c 
 from Approver__c where  reason__c= :c.reason__c and  Category__c=:c.Category__c order by Bill__c asc];
 assigned = false;
}
}
if(lstApprover.size()>0 && c.Status__c!='Approved'){
    
for(Approver__c tmplstApprover :  lstApprover ){
if(assigned == false && c.Bill__c < tmplstApprover.Bill__c){
            c.Approver_1__c=tmplstApprover.Approver_1__c;
            c.Approver_2__c=tmplstApprover.Approver_2__c;
             c.Approver__c= tmplstApprover.id; 
            assigned = true;
          }
    }
}

}

Thanks  in Advance.
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@Nano Randy:

  Looks like your the code you pasted above is not bulkified. To escape from hitting the governor limit while using data loader you change the batch size to some value lower than 100 which will solve the issue in case of data loader. You might need to change/bulkify the code, for bulkifying concepts take a look at the below link:

https://developer.salesforce.com/page/Best_Practice%3A_Bulkify_Your_Code


Hope it helps:

Thanks,
Balaji
TechnozChampTechnozChamp
You are using SOQL query inside For loop which causes the governor limit to hit. Please follow the good practices.
http://technozchamps.blogspot.com/2015/01/salesforce-trigger-best-practices.html