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
Ad_InfosysAd_Infosys 

Too many SOQL in test coverage

I am facing a show stopper problem.
I ahve developed an apex code in Apex classes. These classes have methods which are called between each other. Each class has several number of SOQLs but in a particular context only few are executed(This is well in limit of 100 SOQLs)
 
Now when I create the code coverage, I have to have cummulative coverage. In test coverage while covering scenerios I get across Too many SOQL 101. I am struck at 60% code coverage.
 
Kindly suggest me a way out. This hidrance wont allow codes to move to Production.
 
jpizzalajpizzala
Could you post some of your code so we can see where it is causing problems?

Have you reviewed the Apex documentation to ensure that you are following the recommended guidelines for governor limations (i.e. do not make SOQL calls within a loop)?  Keep in mind that, since your triggers seem to fire each other to some extent, TriggerA may not have SOQL within a loop, but TriggerA could be calling TriggerB within a loop where TriggerB executes a SOQL call (thus executing TriggerB's SOQL call multiple times with a single execution of TriggerA).
Ad_InfosysAd_Infosys
This code does sorting, filtering on certain criterias which come somehow... the SOQLs are well inside if-else.. In a single context they are well below SOQL limit. but see in Code coverage I have to cover them all. This is the issue. I have to run all SOQL. 
 
 
if(Ftype=='Created Date'){
        //opda = GetPipelineFilter_Crdt_AT.GetPipeline_CreatdtAT(adid,Ftype,Frmdt,todt,stype,sorder);
        }
    else if(Ftype=='Scheduled Close Date'){
        //opda = GetPipelineFilter_Cldt_AT.GetPipeline_ClosedtAT(adid,Ftype,Frmdt,todt,stype,sorder);
        }
    else if(Ftype=='Last Modified Date'){
        //opda = GetPipelineFilter_Modt_AT.GetPipeline_ModifdtAT(adid,Ftype,Frmdt,todt,stype,sorder);
        }
    /* If no Filter criteria is specified */
    else{
       
        /* Check the sorting criteria specified by the user and further check the sorting order to manipulate the result extracted. Select the open tasks, take out the opportunities, contacts from opportunitycontactrole and tasks */
        if(stype =='Applicant Name'){
            if(sorder =='desc'){
                opda.optec=[select Name from Obj_application_data__c where AppTaker_AdEnt_Id__c=:adid and islatest__c=true and Application_Entry_Date__c>=Last_month  order by name desc nulls last];
                }
            else{
                opda.optec=[select Name from Obj_application_data__c where AppTaker_AdEnt_Id__c=:adid and islatest__c=true and Application_Entry_Date__c>=Last_month  order by name asc nulls last];
                }
            }
        else if(stype =='Application Number'){
            if(sorder =='desc'){
                opda.optec=[select Name from Obj_application_data__c where AppTaker_AdEnt_Id__c=:adid and islatest__c=true and Application_Entry_Date__c>=Last_month  order by Application_Number__c desc nulls last];
                }
            else{
                opda.optec=[select Name from Obj_application_data__c where AppTaker_AdEnt_Id__c=:adid  and islatest__c=true and Application_Entry_Date__c>=Last_month  order by Application_Number__c asc nulls last];
                }
            }  
       
        else if(stype =='Home Phone Number'){
            if(sorder =='desc'){
                opda.optec=[select Name from Obj_application_data__c where AppTaker_AdEnt_Id__c=:adid  and islatest__c=true and Application_Entry_Date__c>=Last_month  order by Home_Phone__c desc nulls last];
                }
            else{
                opda.optec=[select Name from Obj_application_data__c where AppTaker_AdEnt_Id__c=:adid  and islatest__c=true and Application_Entry_Date__c>=Last_month  order by Home_Phone__c asc nulls last];
                }
            }  
        else if(stype =='# of pending'){
            if(sorder =='desc'){
                opda.optec=[select Name from Obj_application_data__c where AppTaker_AdEnt_Id__c=:adid  and islatest__c=true and Application_Entry_Date__c>=Last_month  order by outstanding_stips__c desc nulls last];
                }
            else{
                opda.optec=[select Name from Obj_application_data__c where AppTaker_AdEnt_Id__c=:adid  and islatest__c=true and Application_Entry_Date__c>=Last_month  order by outstanding_stips__c asc nulls last];
                }
            }  
        else if(stype =='Closing State'){
            if(sorder =='desc'){
                opda.optec=[select Name from Obj_application_data__c where AppTaker_AdEnt_Id__c=:adid  and islatest__c=true and Application_Entry_Date__c>=Last_month  order by State__c desc nulls last];
                }
            else{
                opda.optec=[select Name from Obj_application_data__c where AppTaker_AdEnt_Id__c=:adid   and islatest__c=true and Application_Entry_Date__c>=Last_month  order by State__c asc nulls last];
                }
            }  
        else if(stype =='Best Contact Time'){
            if(sorder =='desc'){
                opda.optec=[select Name from Obj_application_data__c where AppTaker_AdEnt_Id__c=:adid  and islatest__c=true and Application_Entry_Date__c>=Last_month  order by Best_Time_to_Contact__c desc nulls last];
                }
            else{
                opda.optec=[select Name from Obj_application_data__c where AppTaker_AdEnt_Id__c=:adid  and islatest__c=true and Application_Entry_Date__c>=Last_month  order by Best_Time_to_Contact__c asc nulls last];
                }
            }  
        else if(stype =='Best Contact Method'){
            if(sorder =='desc'){
                opda.optec=[select Name from Obj_application_data__c where AppTaker_AdEnt_Id__c=:adid  and islatest__c=true and Application_Entry_Date__c>=Last_month  order by best_method_of_contact__c desc nulls last];
                }
            else{
                opda.optec=[select Name from Obj_application_data__c where AppTaker_AdEnt_Id__c=:adid  and islatest__c=true and Application_Entry_Date__c>=Last_month  order by best_method_of_contact__c asc nulls last];
                }
            }  
        else if(stype =='Contact Email'){
            if(sorder =='desc'){
                opda.optec=[select Name from Obj_application_data__c where AppTaker_AdEnt_Id__c=:adid  and islatest__c=true and Application_Entry_Date__c>=Last_month  order by contact_email__c desc nulls last];
                }
            else{
                opda.optec=[select Name from Obj_application_data__c where AppTaker_AdEnt_Id__c=:adid  and islatest__c=true and Application_Entry_Date__c>=Last_month  order by contact_email__c asc nulls last];
                }
            }  
        else if(stype =='Cell Number'){
            if(sorder =='desc'){
                opda.optec=[select Name from Obj_application_data__c where AppTaker_AdEnt_Id__c=:adid  and islatest__c=true and Application_Entry_Date__c>=Last_month  order by otherphone__c desc nulls last];
                }
            else{
                opda.optec=[select Name, from Obj_application_data__c where AppTaker_AdEnt_Id__c=:adid  and islatest__c=true and Application_Entry_Date__c>=Last_month  order by otherphone__c asc nulls last];
                }
            }