You need to sign in to do that
Don't have an account?
redavis13
Getting Error
Error: Invalid Data.
Review all error messages below to correct your data.
common.apex.runtime.impl.TriggerExecutionException: Apex trigger UpdateLead caused an unexpected exception, contact your administrator: UpdateLead: execution of BeforeUpdate caused by: System.Exception: Too many query rows: 1001: Trigger.UpdateLead: line 7, column 24
Review all error messages below to correct your data.
common.apex.runtime.impl.TriggerExecutionException: Apex trigger UpdateLead caused an unexpected exception, contact your administrator: UpdateLead: execution of BeforeUpdate caused by: System.Exception: Too many query rows: 1001: Trigger.UpdateLead: line 7, column 24
I have a list of users, and I need to cycle through that list to find a specific users, to get thier appropriate managerid to set that value for the record in question.
Thanks in advance.
It sounds like you are hitting the governor limit that lists can only hold 1000 items. This limit is being removed in Spring 10, so it might not be a problem, otherwise you can use SOQL for loops to iterate large data sets.
Can't I take and put this query result in a Map or List with an Id, and the value I need based on that ID lookup. Can I create a class that populates this list or map, and refer to that?
You can, as long as there are not more than 1000 results. If there are, you get the governor limit error that you have received.
If you can post your code, we can probably give you more specific assistance.
Hi,
Why don't you try to use the query in the for loop ? You can find the reference here : http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_loops_for_SOQL.htm
HS
Thank you all for all of your advice.
I used the SOQL For loop and now I am getting this error in the debug logs:
09:39:46.712|EXCEPTION_THROWN|[13,5]|System.Exception: Too many script statements: 20001
09:39:46.712|FATAL_ERROR|System.Exception: Too many script statements: 20001
Here is the code:
// Before Update and Before Insert
if (Trigger.isUpdate && Trigger.isBefore){List<User> userMgrList = new List<User>();
for(User userMgr : [Select u.ManagerId, u.Id From User u where u.IsActive = true and u.ManagerId <> '']){userMgrList.add(userMgr);
}
for(integer i = 0; i<trigger.new.size();i++){for(integer j = 0; j < userMgrList.size(); j++){
if(userMgrList[j].Id == trigger.new[i].OwnerId){ trigger.new[i].Owner_Manager__c = userMgrList[j].Id;}
}
}
}
You've now hit another governor limit, which is mainly going to be down to your nested loops.
You'd do better to put your userMgr data into a map, keyed by id. Then rather than iterating the list and looking for matches, you could simply get the entry in the map where the key matches trigger.new[i].ownerid .