You need to sign in to do that
Don't have an account?
Trigger Issue - Wrong Error Message? - Other Issues
Here is the error message in the email (IDs hidden):
Apex script unhandled trigger exception by user/organization: 005xxxxxxxxxxxx/00Dxxxxxxxxxxxx TRIGGERNAME: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0 with id 00kxxxxxxxxxxxx; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id] Trigger.TRIGGERNAME: line 70, column 1
The trigger copies a custom object that holds the products for Lead. When the Lead is converted to an Opportunity, the trigger creates an OpportunityLineItem for each Lead Product, like so (after update on the Lead, pbIDs is a Map<string, Id> with the PricebookEntry IDs):
for(LeadProduct__c prod:leadProducts) { OpportunityLineItem newProd = new OpportunityLineItem(); newProd.PricebookEntryId = prod.PricebookEntry__c; newProd.OpportunityId = l.ConvertedOpportunityId; newProd.Quantity = prod.Quantity__c; newProducts.add(newProd); } insert newProducts;
I was thinking that there may be some trigger doing an Insert with an ID, but wouldn't the error email have the name of that trigger? It has the name of mine. And as you can clearly see, my trigger is not specifying the ID for the records that it's inserting.
What's even stranger is that the User ID specified in the email does NOT exist. I checked it, and got an "Insufficient Privileges: You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary." I send the ID to my system admin, and THEY get the same exact issue. So I'm thinking that this may be occurring in a test, since this process is working correctly, except for one user that doesn't actually exist.
Possibly related:
http://boards.developerforce.com/t5/Apex-Code-Development/Issues-with-managing-the-Account-Team-through-a-Trigger/m-p/183816#M29548
All Answers
More information:
Possibly related:
http://boards.developerforce.com/t5/Apex-Code-Development/Issues-with-managing-the-Account-Team-through-a-Trigger/m-p/183816#M29548
Looks like that was the issue.
I was declaring "newProducts" outside of the loop through the trigger Leads. Moved the declaration inside, haven't had any more error emails.