Hi can any one help me out to resolve the issue when ever user clicks on a tab for example like Doctors after clicking that tab.

Too many SOQL queries: 101

The previous error is displayed. Below is the controller Constructor code. Can u guide me to resolve the issue?

// Constructor
        public Msn_PromotionalStock_report_con(){
            panel = false;
            pbValue = false;
            norecfin = false;
            userFinalList = new set<Id>();
            set<Id> setUser = new set<Id>();
             allUsers = new set<Id>();
            allUsers = getRoleSubordinateUsers(setUser);
        userobj = [Select id,Profile.Name,country,Region__c FROM User Where id =: userinfo.getuserId()];
        prmSetForMR = new set<Id>();
        if(userobj.Profile.Name == 'Medical Representative'){
            SelectedMedicalrep = userinfo.getuserID();
        else if(userobj.Profile.Name == 'Regional Manager'){
            SelectedRegion = userobj.Region__c;
            countrysSet = new set<String>();
            for(Country__c cnt : [Select id,Name FROM Country__c Where Regional_Head__c =:userinfo.getuserId()]){

        else if(userobj.Profile.Name == 'Country Manager'){
            SelectedCountry =  userobj.country;
        usrLst = [Select id,Name FROM User Where id IN : allUsers And Profile.Name = 'Medical Representative' Order By Name Asc];
        contentType = '';
        renFilter = true;
        htmlver = 'html-5.0'; 
        isPagination = false;
        prmSetForDownload = new set<Id>();

        usr = [Select id,name,country,profile.name,region__c FROM USER Where id =: userinfo.getUserId()];

        filecontent = '<h2>Promotional Stock Utilization</h2><table id="down" border="1"><tr><td><b>S.No</b></td><td><b>Input Name</b></td><td><b>Brand Name</b></td><td><b>Input Type</b></td><td><b>Total Qty</b></td><td><b>Allocated By</b></td><td><b>Allocated Date</b></td><td><b>Country</b></td><td><table id="down" border="1"><tr><td><b>Allocated to MR</b></td><td><b>Allocated to MR Date</b></td><td><b>Qty Allocated</b></td><td><b>Qty Utilized</b></td><td><table id="down" border="1"><tr><td><b>Presented to</b></td><td><b>Doctor/Pharmacy</b></td><td><b>Presented Date</b></td></tr></table></td></tr></table></td></tr>';
        noRecordsFound = '';

  • 6
    I don't think the error comes from the code you posted. Jun 28, 2017 at 7:04
  • 1
    Have you done a search on the error message. This has been asked and answered many times. Also what Martin said. This may have been the code that hit the limit but not the cause of the excessive soql usage
    – Eric
    Jun 28, 2017 at 7:33
  • Just make sure you're not calling this function from inside a loop... but yeah, Eric is right, there are a ton of questions about this. Jun 28, 2017 at 8:05

1 Answer 1


Code snippet posted doesn't have any problems. Seems like a problem with getRoleSubordinateUsers method.

Setup debug logs to find out the SOQL queries in your code.

To setup debug logs: Go to Setup -> Debug Logs

Edit a User trace flag and set User as logged in user, start time as current time, end time as current time + 1 hour and Save Click on Filters link and change Database to finest.

Load your page throwing the exception in a separate tab and reload debug logs tab after you encounter exception.

View / Download log file. Every SOQL statement is logged and that should help.

Update 1: I'd appreciate if you'd provide reason for down vote.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .