- February 9, 2018 at 12:03 pm #25177Rahul #63
How to handle “Too many soql queries:101” problem in Salesforce?
when I close a case then 32 queries run in the whole process to close a single case.
Now I want to run a schedule in which I am fetching a list of cases which will be always more than 50-60 per day by this I am getting an error “Too many SOQL queries:101″ (because in 3 case soql queries will be 3*32=96 near about to 100).
so please tell me how to handle this process that in one time I call only for 3 cases batched.
Rahul KumarFebruary 10, 2018 at 2:15 am #25181GUHA ANANADH #135
Don’t use the query inside any for loops. Instead, query the list of all records and store it in a list or set, and loop through that list to do the set of logic you wanted to do. No queries inside a for loop is the ground rule for apex programming. Google examples for this approach, there are plenty of examples you can find. Happy coding.February 10, 2018 at 5:46 am #25182Rahul #63
Thanks for reply, but i am not calling to query in loop .
Here is my code:
listCaseTCR = [SELECT id,RV_Consignment_Status__c ,CN_Number__c,Case_Category__c,Issue_Type__c,Sub_Title__c
FROM Case WHERE Issue_Type__c =:’Tech – CR’ AND Sub_Title__c IN:subtitle AND CN_Number__c!=’NULL’ AND Status!=’Closed’ AND RV_Is_Parent__c=:FALSE];
//for(Case cr : listCaseTCR)
total = listCaseTCR.size();
system.debug(‘total cases of Tech – CR are :’+total);
if(cnumber!=Null && cnumber!=”)
now problem start from here that when i am calling trackconsignment(cnumber); method then this is using 32 soql queries to closed a case and i have a lot of cases in list listCaseTCR so it’s firing 101 error.
how to handle it?
Please Register to reply to this topic. /