You need to sign in to do that
Don't have an account?
Arun K
Hittng governor limits
I know I am doing the wrong way as I hittin the governor limits.
But I am not getting how to change the code as it is behaving
What needs to be done
here is the code
public approval_dynamic_differential() { Dynamiclist = new list< Dynamic_territory_differential>(); UserTerritory ustr = [Select TerritoryId ,UserId From UserTerritory where UserId = :UserInfo.getUserId()]; for(Territory terr :[SELECT Id ,name FROM Territory where ParentTerritoryId =:ustr.TerritoryId]) { UserTerritory user = [SELECT Id, UserId, TerritoryId FROM UserTerritory where TerritoryId = :terr.Id]; User userid = [select Id,Name From User Where id = :user.Userid]; TransferAcc = [select id,name,Active__c,Specialization_differential__c,Reason_For_Change__c ,Approval__c,Billingcity,Billingstate,Original_Calls_Total__c,Notes__c from Account WHERE OwnerId=:userid.id and Approval__c='Pending'and Submit__c=True]; UpdateAcc = [select id,name,Active__c,Approval__c,Specialization_differential__c,Billingcity,Billingstate ,(select id,name,Original_CallString__c,Updated_CallString__c,Call_String_Status__c from Call_Strings__r where Call_String_Status__c='Pending') from Account WHERE OwnerId=:userid.id and Approval__c!='Pending' and Submit__c=True]; d1= new Dynamic_territory_differential(); d1.TerritoryId = terr; d1.userTerrid = user; d1.username = userid; d1.Accountslist = TransferAcc; d1.UpdateAcclist = UpdateAcc ; Dynamiclist.add(d1); system.debug('size======='+d1.UpdateAcclist.size()); } getdynamicdifferential(); }
Here's a stab at it... I don't have too much time to optimize it but it should get you in the right direction.
I've removed all the SOQL from the loop and instead built a map relative to what logic you were doing in the code. As this was written on the fly it may not compile immediately.
All Answers
hi,
What error message do you get?
If it is about 101 SOQL limit, then it is becuase of your select queries within for loop. Implment that logic without having soql select query within for loop.
Hit kusdos and marka s answer if this reply helps you.
thanks,
Yes, It is 101 soql stmts error.
I want to loop through those soql stms and I couldnt do it.
Can u send the update one.
Here's a stab at it... I don't have too much time to optimize it but it should get you in the right direction.
I've removed all the SOQL from the loop and instead built a map relative to what logic you were doing in the code. As this was written on the fly it may not compile immediately.