You need to sign in to do that
Don't have an account?
Can I use Batching to avoid 500 record governor limits, if so, how?
I have tried batching by filtering results by a range called "nameRange". I can paste the code into the System Log window with some hard coded values for the dates, and it seems to work fine. When I test in the Sandbox, I hit the query governor limit. Any ideas?
String[] nameRange = new String[]{'KT 045000','KT 050000','KT 055000','KT 060000','KT 065000'};
For (Integer i=0; i < nameRange.size()-1;i++)
{
for ( User_Month_KPI__c[] UserKPIs :
[
select
u.OwnerId,
u.active_accounts_actual__c,
u.APNrent_month_revenue_actual__c,
u.revenue_new_accounts_actual__c,
u.new_accounts_signed_actual__c,
u.APN_Month__c,
u.APN_Year__c,
u.Month_Start_date__c,
u.Month_End_date__c,
u.avg_rev_per_account_actual__c,
u.IPI_bookings_count__c,
u.Id
from User_Month_KPI__c u
where u.APN_Year__c = :APNYear
and u.APN_Month__c = :APNMonth
and u.Name >= :nameRange[i]
and u.Name < :nameRange[i+1]
limit 500] )
{
for (User_Month_KPI__c UserKPI : UserKPIs)
{
this.getCurrentSet().put(UserKPI.OwnerId,UserKPI);
UserKPI.Month_Start_date__c = APNMonthStartDate;
UserKPI.Month_End_date__c = APNMonthEndDate;
Records++;
} // End FOR
} // End FOR
} // End FOR
CurrentSet = 0;