• #25177
    Salesforce | Rahul Rahul #56

    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 Kumar



    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.

    Salesforce | Rahul Rahul #56

    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?


    Rahul Kumar

Viewing 3 posts - 1 through 3 (of 3 total)

Please to reply to this topic.


We're not around right now. But you can send us an email and we'll get back to you, asap.


About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2019 Forcetalks. All Right Reserved.

Log in with your credentials


Forgot your details?