You need to sign in to do that
Don't have an account?
trublu
Trigger - Too many script statements: 50001
Hi all,
In order to batch up the soql queries within my Account trigger (trigger on account after update), I have some loops to build the id lists (account, user, group, parent account) up front in the trigger. However, instead of getting "too many SOQL script" error, I am now getting "too many statement script" when the trigger is invoked via batch account update.
Could anyone please help??? SF is so restrictive that I cannot really do anything with triggers!!!
Thanks a lot.
PS I have to build out all these id lists because I need to insert AccountShare records based on a specified user in a custom field on Account... Frankly, the Account Trigger does not really update the account record itself, but to add the appropriate AccountShare records based on the user role of that specified user on the custom Account field.
======================================================================
Force.com Sandbox
Apex script unhandled trigger exception by user/organization:
updateAccountAfterUpdate: execution of AfterUpdate
caused by: System.Exception: Too many script statements: 50001
Class.ProspectManagerManager.handleAccountSharing: line 62, column 21
Trigger.updateAccountAfterUpdate: line 13, column 9
//1. childAccount
for (Integer i = 0; i < accountList.size(); i++) {
childAccountIdMap.put(i, accountList[i].id);
childAccountIdList.add(accountList[i].id);
prospectManagerUserIdMap.put(i, accountList[i].Prospect_Manager__c);
prospectManagerUserIdList.add(accountList[i].Prospect_Manager__c);
}
try{
childAccountList = [SELECT id, Prospect_Manager__c from Account WHERE Id in :childAccountIdList];
}
catch(Exception e)
{
System.debug('childAccountList is null');
}
if (childAccountList != null) {
for (Integer i = 0; i < accountList.size(); i++) {
for (Integer ii = 0; ii < childAccountList.size(); ii++) {
Account thisAccount = childAccountList.get(ii);
if ((''+thisAccount.id).equals(accountList[i].id)){
childAccountMap.put(i, thisAccount);
continue;
}
}
}
}
//2. prospectManager
try{
prospectManagerUserList = [select userroleid, id, name, Development_Unit__c from User where id in :prospectManagerUserIdList];
}
catch(Exception e)
{
System.debug('prospectManagerUserList is null');
}
if (prospectManagerUserList != null && !prospectManagerUserList.isempty()) {
for (Integer i = 0; i < accountList.size(); i++) {
for (Integer ii = 0; ii < prospectManagerUserList.size(); ii++) {
User thisMgr = prospectManagerUserList.get(ii);
if (thisMgr != null && (''+thisMgr.id).equals(accountList[i].prospect_manager__c)){
prospectManagerUserMap.put(i, thisMgr);
continue;
}
}
}
}
//3. GROUP
AND ONE MORE SECTION FOR GROUP....
Simon,
I am having the same issue, , here is my trigger...will the same solution apply in this case?
-Thanks