0

The error occurs when loading the page for a custom object.

My understanding is that this error means a query did not return any results, but I don't know how to begin identifying what query that is.

For context, I am not a developer. I have a cursory knowledge of coding and am decent with SQL/SOQL.

I realize this question is sparse, I'm not sure what more detail to add. Any feedback is appreciated.

1
  • With the information you've given so far, I was able to give you an answer about how to find the issue. Fixing it is another matter though. Generally speaking, including the problematic code, pointing to the specific line that is experiencing the issue, and giving us an overview of what the objective of the code/lightning component/workflow/visualforce page/etc... is will help you get more accurate and specific answers. – Derek F Oct 11 '19 at 15:59
0

SOQL always returns results as a List<SObject>, even if there are no rows to return (in which case, the list would be empty/contain no items).

When we expect a single row to be returned, Salesforce allows us to take a bit of a shortcut. Instead of

List<Account> accountsList = [SELECT Id FROM Account LIMIT 1];
Account myAcc = accountsList[0];

We can just assign the result of the query to a single variable

Account myAcc = [SELECT Id FROM Account LIMIT 1];

The problem is that, for this shortcut to work, the query must return exactly one row. If it returns no rows, you run into the error you're seeing (a slightly different error is given if the query returns 2+ rows).

The error message should also include a stack trace (basically, the list of classes and methods that were called that ended up giving you your error). This should tell you both the class name and the approximate line number that the error occurred on.

Start at the top of your list, and look at the indicated line number until you find a query being assigned to a single variable instead of a collection.

Finding the issue is one thing. Fixing it will require some developer skills.

5
  • Thanks Derek. Is the stack trace what I see in Chrome's dev tools console? – Vertical Sunlight Oct 11 '19 at 16:01
  • @VerticalSunlight Nope, the stack trace should be part of the error message. An example of a stack trace from one of my sandboxes is Class.AtlasHierarchyBuilder.doBeforeInsert: line 1517, column 1 Class.AtlasHierarchyBuilder.insertParent: line 1481, column 1 Class.AtlasHierarchyBuilder.createHierarchy: line 1715, column 1 Class.AtlasOrderEvent.Package_Created.run: line 81, column 1 Class.AtlasEventDispatcher.handlePOST: line 228, column 1 and you'd start looking for the issue in the doBeforeInsert() method of AtlasHierarchyBuilder first. – Derek F Oct 11 '19 at 16:05
  • I'm not sure where to find that. All I see is the text “List has no rows for assignment to SObject An unexpected error has occurred. Your development organization has been notified.” on a blank white page. – Vertical Sunlight Oct 11 '19 at 16:11
  • @VerticalSunlight Then to get more of an idea of what's wrong, you could open the developer console and cause the error to happen again to get a log file and pick through the end of the log. Honestly though, the issue is probably in a controller extension class. If you look through the buttons, links, and actions for your custom object, editing the "view" action should tell you what Visualforce page is being used. Once you navigate to the Visualforce page, the class name given in the "extensions" attribute of the <apex:page> tag is the class that you should look at. – Derek F Oct 11 '19 at 16:20
  • or, turn on developer mode in the User record and then the VF page will show the stacktrace – cropredy Oct 11 '19 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.