You need to sign in to do that
Don't have an account?

Too many SOQL queries: 101..
Hi dears,
Am getting err too many queries..Here attach my classes, Actually where do i write list collection please can anyone tel me...
public PageReference Save() { /////////// LEVEL 1 /////////////////// List<level1s__c> selectLevel1 = new List<level1s__c>(); List<level1s__c> selectedLevel1 = new List<level1s__c>(); for(Level1sClass con: getList1Details()) { system.debug('con'+con.selected); if(con.selected == true) { system.debug('firstCCCCCCCCCC:'+con.lev1); selectedLevel1.add(con.lev1); } Level1__c[] levl1= [Select Id from Level1__c where Account__c=: ApexPages.currentPage().getParameters().get('id')]; delete levl1; if(selectedLevel1 != null) { for(level1s__c cCon: selectedLevel1) { system.debug('CCCCCCCCCC:'+cCon+'\n'); string acctid =ApexPages.currentPage().getParameters().get('id'); List<Level1__c> lvl1obj= new Level1__c[0]; lvl1obj.add(new Level1__c(Name='Level1',Account__c=acctid,cLevel1__c=cCon.id)); insert lvl1obj; } } /////////////// LEVEL 2 ////////////// List<level2s__c> selectLevel2 = new List<level2s__c>(); List<level2s__c> selectedLevel2 = new List<level2s__c>(); for(Level2sClass con1 : getList2Details(con.lev1)) { system.debug('con'+con.selected); if(con.selected == true) { system.debug('secondCCCCCCCCCC:'+con.lev2); selectedLevel2.add(con1.lev2); } } Level2__c[] levl2= [Select Id from Level2__c where Account__c=: ApexPages.currentPage().getParameters().get('id')]; delete levl2; if(selectedLevel2 != null) { for(level2s__c cCon : selectedLevel2) { system.debug('CCCCCCCCCC:'+cCon+'\n'); string acctid =ApexPages.currentPage().getParameters().get('id'); List<Level2__c> lvl2obj= new Level2__c[0]; lvl2obj.add(new Level2__c(Name='Level2',Account__c=acctid,cLevel2__c=cCon.id)); insert lvl2obj; } } } return null; }
The problem is this line:
You placed the SELECT statement within the for loop, causing the 'too many queries' issue. If you rewrite the code to mimic the rest of the code below, you should be able to avoid the error.
Alternatively review this blog, to see how you can rewrite your code.
This is the modified class to overcome 101 issue
You will still face the issue of "Too many SOQL Queries" even after you modified the class as the query is still inside the for loop
this line
is still inside this for loop