You need to sign in to do that
Don't have an account?
Sebastian Page
Governing limit Exception error on my batch class
Hi All ,
i am getting error of governing limit error is " System.LimitException: Too many query rows: 50001"
Batch apex class-
global class SSO_User_count implements database.Batchable<sObject> {
global database.QueryLocator start(database.BatchableContext bc)
{
string query='Select id from account';
return database.getQueryLocator(query);
}
global void execute(database.BatchableContext bc ,List<account> scope)
{
List<Account> updateacc=new List<Account>();
list<account> acclist=[select id,SSO_User_Count__c,ispartner ,iscustomerportal from account where Ispartner=true and IsCustomerPortal=true];
for(Account acc:acclist){
List<user>lstusr=[select id FROM User where isActive=true and User.Profile.UserLicense.Name='Overage High Volume Customer Portal' and accountid=:Acc.id];
// acc.SSO_User_Count__c=lstusr.size();
acc.SSO_User_Count__c=lstusr.size();
scope.add(acc);
}
update scope;
}
global void finish(database.BatchableContext bc)
{
}
}
i am getting error of governing limit error is " System.LimitException: Too many query rows: 50001"
Batch apex class-
global class SSO_User_count implements database.Batchable<sObject> {
global database.QueryLocator start(database.BatchableContext bc)
{
string query='Select id from account';
return database.getQueryLocator(query);
}
global void execute(database.BatchableContext bc ,List<account> scope)
{
List<Account> updateacc=new List<Account>();
list<account> acclist=[select id,SSO_User_Count__c,ispartner ,iscustomerportal from account where Ispartner=true and IsCustomerPortal=true];
for(Account acc:acclist){
List<user>lstusr=[select id FROM User where isActive=true and User.Profile.UserLicense.Name='Overage High Volume Customer Portal' and accountid=:Acc.id];
// acc.SSO_User_Count__c=lstusr.size();
acc.SSO_User_Count__c=lstusr.size();
scope.add(acc);
}
update scope;
}
global void finish(database.BatchableContext bc)
{
}
}
try something like :
Caveat: not tested with actual data
Regards
Andrew
All Answers
try something like :
Caveat: not tested with actual data
Regards
Andrew
Thanks & Regards,
Abhishek Singh.
Thanks for quick response. could you explain me one line that are you using in your code .
SELECT AccountId accId, COUNT(Id) uCount FROM User WHERE isActive=true AND User.Profile.UserLicense.Name='Overage High Volume Customer Portal' AND accountid In :accIds GROUP BY AccountId.
In this query you are write AccountId accId togather . what its use.
Regards
Sebastian
It is in the context of the AggregrateResult object.
I am assigning an alias (accId) to the field name AccountId.
Whilst the AggregrateResult loop could use the fieldname, eg. I have found that the Aggregrate object query gives a more stable result by using an alias instead of the field name. By more stable, I mean I have less problems with the code running - sometimes when I have used the fieldname, it is as if the compile recognises the fieldname but it fails to read it a run time.
Glad to help
Andrew
Ones again Thanks for Support .
Regards
Sebastian Page