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

Too many soql error :101 on different trigger when executing a apex class
I am trying to execute the following class from a button. when i set the limit to 9 it wors fine. When i remove limit on the 1st query it throws error on other triggers.
global class DERedistribute{
@future
webservice static void DERedistribute(){
List<Lead> l = [SELECT Name,Times_The_Lead_Is_Distributed__c,Hawaii__c,SV_Priority_Hidden__c, Id, AssignToUserId_Hidden__c FROM Lead WHERE IsConverted =false and Hawaii__c = false and To_Be_Distributed__c=true and DE_Synched__c=true and Is_Distributed__c =True];
integer x=0;
List<Team1__c> L1 = [SELECT Name,CheckIn__c From Team1__c Where CheckIn__c = True];
integer i = L1.size();
integer z=1;
for(Team1__c L2 :[SELECT Name,CheckIn__c,UserId__c From Team1__c] )
{
If(L2.CheckIn__c == True)
{
L2.UserId__c = z++;
}
else
{
L2.UserId__c =0;
}
update L2;
}
for(Lead e : l)
{
x++;
decimal y = e.Times_The_Lead_Is_Distributed__c;
e.AssignToUserId_Hidden__c = math.MOD(x, i) + 1;
e.Is_Distributed__c =True;
e.Times_The_Lead_Is_Distributed__c = y +1;
update e;
}
}
}
global class DERedistribute{
@future
webservice static void DERedistribute(){
List<Lead> l = [SELECT Name,Times_The_Lead_Is_Distributed__c,Hawaii__c,SV_Priority_Hidden__c, Id, AssignToUserId_Hidden__c FROM Lead WHERE IsConverted =false and Hawaii__c = false and To_Be_Distributed__c=true and DE_Synched__c=true and Is_Distributed__c =True];
integer x=0;
List<Team1__c> L1 = [SELECT Name,CheckIn__c From Team1__c Where CheckIn__c = True];
integer i = L1.size();
integer z=1;
for(Team1__c L2 :[SELECT Name,CheckIn__c,UserId__c From Team1__c] )
{
If(L2.CheckIn__c == True)
{
L2.UserId__c = z++;
}
else
{
L2.UserId__c =0;
}
update L2;
}
for(Lead e : l)
{
x++;
decimal y = e.Times_The_Lead_Is_Distributed__c;
e.AssignToUserId_Hidden__c = math.MOD(x, i) + 1;
e.Is_Distributed__c =True;
e.Times_The_Lead_Is_Distributed__c = y +1;
update e;
}
}
}
for(Lead e : l)
{
x++;
transient decimal y = e.Times_The_Lead_Is_Distributed__c;
e.AssignToUserId_Hidden__c = math.MOD(x, i) + 1;
AssignToUserId.add(e.AssignToUserId_Hidden__c);
e.Is_Distributed__c =True;
IsDistributed.add(e.Is_Distributed__c);
e.Times_The_Lead_Is_Distributed__c = y +1;
TimesLeadIsDistributed.add(e.Times_The_Lead_Is_Distributed__c);
id.add(e.Id);
transient decimal d =0;
Lead lead = new Lead();
if(AssignToUserId.size()>d)
lead.AssignToUserId_Hidden__c = AssignToUserId[x-1];
if(IsDistributed.size()>d)
lead.Is_Distributed__c = IsDistributed[x-1];
if(TimesLeadIsDistributed.size()>d)
lead.Times_The_Lead_Is_Distributed__c = TimesLeadIsDistributed[x-1];
L3.add(lead);
lead.Id = id[x-1];
d++;
}
if(L3.size()>0)
{
Schema.SObjectField f = Lead.Fields.Id;
Database.UpsertResult[] UpdateResult = Database.UPSERT(L3,f,false);
}