+ Start a Discussion
Adrien SmithAdrien Smith 

Help Needed - Error with trigger thrown when trying to convert leads, update and edit accounts

We recently started experiencing an error with converting leads and editing accounts, which I suspect was caused by inactivating a user who is no longer with our company (since this is the only change we have made in the period before this problem started last week). When a user (any user, even an admin) attempts to convert a lead or make an edit they receive:

Error: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, GenerateNewOrder: execution of AfterInsert caused by: System.QueryException: List has no rows for assignment to SObject Trigger.GenerateNewOrder: line 6, column 1: [] (System Code)


After contacting Salesforce Support they suggested that there was an issue with a trigger that was causing the error we were receiving since the trigger was referencing a user who no longer existed. However, I miffed as to WHICH trigger it may be since we have dozens set up. Salesforce support has suggested the following which is essentially Greek to me and I am not quite sure where to start:

1. Check the Debug logs and get to the line number of the class where it's throwing that error message.

You will get a query on that line number.

Run that query in the developer console and you should get zero records.

This error occurs when query doesn't return any rows. For e.g.

Account a = [select id, name from Account where name = 'test'];

To avoid this exception, create a list of account

List<Account> lstAccount = [select id, name from Account where name = 'test'];
if (lstAccount.size() > 0)
{
Account a = lstAccount.get(0);
}

2. Alternatively, you now know the exception, so you can use try/catch as well.


Any suggestions? I'm really unsure where to start by even narrowing down which trigger it should be, just short of going through each and every one...
girbot56girbot56
Do you know how to setup a debug log and view it? In case you don't
Setup > Admin Setup > Monitoring > debug logs. Select the user you recreating the issue with. Once you have recreated it you will and refreshed the debug log list you will see an entry with an operation similiar to your error above. View this log and you should be able to get the extra detail there.