SFDCian – Best Salesforce Consultant & Architect

Apex error – ‘List has no rows for assignment to SObject’

The error “List has no rows for assignment to SObject” occurs when query doesn’t return any rows.

Resolution   

While a SELECT normally returns an array/list, these statements are using the shorthand syntax that assumes only one row is returned. What’s not obvious is that it also assumes that exactly one row is returned! Although this is unlikely to occur for Contact, it is highly likely to occur for any custom objects you create, especially when a WHERE statement is used that might return zero rows, such as: 

The above code will fail if there is no Player__c record with the matching username. It doesn’t actually return a null.  It would be safer to do the following:

It’s one of those situations for which you would not normally think of creating a test, so it’s safer to just avoid the possibility.

Related Posts

Salesforce: opportunity clone for each opportunity contact role along with opportunity products, are you building lightning app with locker services.

Common fix to a "Error: List has no rows for assignment to SObject" error received when Rejecting Applications. Oct 25, 2018 • Knowledge

Error when rejecting applications: list has no rows for assignment to sobject, information.

Salesforce Error: List has no rows for assignment to SObject

Feb 16, 2024 • knowledge, information.

This article discusses solutions for Field Security and Object Permissions Errors.  Alternative; create an iContact for Salesforce Permission Set - read more here . Examples of Salesforce Field Security Errors:

  • Error: [User Profile] does not have permission to...  iContact Sent Message.
  • Error: List has no rows for assignment to SObject.
  • Error: User unable to update ... Permission Denied. Please check your Field Level Security settings.

These errors can occur for iContact for Salesforce Users that do not have Read Access for iContact Custom Fields. The User will see an error after clicking the button Send to Campaign Members, or the Continue button.  Both errors can be corrected by following the steps below to add Read access for iContact custom fields.  Edit iContact Field Security - First Determine Which Steps to Follow Version 1 or Version 2

*Note; Salesforce offers two profile page layouts.  Check the screen shots below to determine which version of these instructions you should follow; i.e. Version 1 or Version 2.

1.) In Salesforce, click on Setup.

2.) On the left side of the page is a menu.  Expand Users / (Manage Users).

3.) Click on Profiles.

4.) Locate the Profile for *the User that received the error*.

5.) Click the Profile for the User that triggered the error . (For example System Administrator , or Marketing User, etc.)

6.) Check Salesforce Profile page layout;

  • If the Profile page appears like Version 1 , go to the next page for Version 1 steps.
  • If the Profile page appears like Version 2 , skip down to Version 2 steps.

Versions1and2.jpg

iContact Field Security Instructions Version 1 Note; Version 1 for accounts with Enhanced Profile User Interface Disabled.

5.) Click the Profile for the User that triggered the error . (For example System Administrator , or Marketing User, etc.) 6.) Scroll to the Section called "Custom Field-Level Security". (Note; try using Browser Search; hold down the Control key and F key to open a search bar) 7.) Locate "iContact Sent Message" > click on "View".

8.) Click Edit.

9.) Look for boxes that are unchecked.

*(note; ignore boxes that are greyed out, or that cannot be checked.)

10.) If you see a box that is unchecked, check both Read Access and Edit Access.

11.) Your goal is to check all boxes that you are able to check. *(note; scroll down to view all Fields.)

12.) Click the Save button, after making changes.

13.) Try again to send a message, or update statistics.

14.) If you continue to see an error, please repeat the steps (1-12) for the following;

  • iContact Clicked Links
  • iContact Global Statistics
  • iContact Message Statistics
  • iContact Temp Recipients
  • iContact Configurations

15.) Try again to send a message, or update statistics.

iContact Field Security Instructions Version 2 Note; Version 2 for accounts with Enhanced Profile User Interface Enabled.

5.) Click the Profile for the User that triggered the error. (For example System Administrator , or Marketing User, etc.)

6.) Click on Object Settings.

7.) Locate "iContact Sent Messages" click to open. (Note; the list of Objects are in Alpha order, scroll down to the letter “i”)

9.) Go to the section “Field Permissions.”

10.) Look for boxes that are unchecked. *(note; ignore boxes that are greyed out, or that cannot be checked.)

11.) If you see a box that is unchecked, check both Read Access and Edit Access.

12.) Your goal is to check all boxes that you are able to check. *(note; scroll down to view all Fields.)

13.) Click the Save button, after making changes.

14.) Try again to send a message, or update statistics.

15.) If you see an error, please repeat the steps (1-13) for the following;

16.) Try again to send a message, or update statistics.

Related Articles

  • Number of Views 402
  • Number of Views 668
  • Number of Views 1.58K
  • Number of Views 931
  • Number of Views 713

Trending Articles

  • Custom DKIM Setup - Improve Email Delivery and Inbox Placement
  • DKIM DNS Setup for some popular hosting providers
  • Common File Upload Issues
  • Email Authentication: DKIM, SPF, and DMARC Information
  • Resubscribing Contacts who are Unsubscribed or Do Not Contact

IMAGES

  1. Salesforce: List has no rows for assignment to SObject in a test class

    no rows for assignment to sobject

  2. Salesforce: List has no rows for assignment to SObject

    no rows for assignment to sobject

  3. System.QueryException: List has no rows for assignment to SObject for

    no rows for assignment to sobject

  4. Salesforce: Visualforce System.QueryException: List has no rows for

    no rows for assignment to sobject

  5. Understanding 'List has no rows for assignment to SObject' in a trigger

    no rows for assignment to sobject

  6. Salesforce: Test Class

    no rows for assignment to sobject

VIDEO

  1. Power Upright Rows

  2. Session 4 SObject DataTypes Variables mp4

  3. Unbalanced Assignment Problem

  4. Across the APIs: Salesforce REST SObject Insert and Update

  5. Lecture 05 || Microsoft Word

  6. 36.SalesforceAdminPlatformEventsCustomLabelsAutoLaunchedFlowNoTriggerFlowBestPracticesFlowOrchestrat

COMMENTS

  1. Apex error 'List has no rows for assignment to SObject'

    What's not obvious is that it also assumes that exactly one row is returned! Although this is unlikely to occur for Contact, it is highly likely to occur for any custom objects you create, especially when a WHERE statement is used that might return zero rows, such as:

  2. List has no rows for assignment to SObject

    This is resulting in no records being returned and Salesforce throwing the System.QueryException: List has no rows for assignment to SObject. Note that this is unlike some other programming languages where you may expect the query to just set your sObject to null. Salesforce's documentation for System.QueryException states it is thrown when ...

  3. List has no rows for assignment to SObject

    If you get more than 1 row and attempt to assign that to your Accountx variable you will get the opposite of your original problem - System.QueryException: List has more than 1 row for assignment to SObject! So one way of guarding against this would be to use Account accountx = [SELECT Id FROM Account LIMIT 1]'. - frup42.

  4. I'm getting "List has no rows for assignment to SObject" error on a

    If the query doesn't return any rows you will get the "List has no rows for assignment to SObject" exception. Instead, assign the results to a list of sObjects and check the size of the list. Then only use the first record in the list if it is present. - Daniel Ballinger.

  5. salesforce

    Impossible. If you're getting "list has no rows to assign to sObject" it means you're assigning to single object. This eliminates getProductsLov(unless you didn't post whole code) because there you assign to a list.. Humo(u)r me and System.debug(JSON.serializePretty(ApexPages.currentPage().getParameters())); in your constructor before firing that query...

  6. Apex error

    What's not obvious is that it also assumes that exactly one row is returned! Although this is unlikely to occur for Contact, it is highly likely to occur for any custom objects you create, especially when a WHERE statement is used that might return zero rows, such as:

  7. apex

    The reason for the failure is 'System.QueryException: List has no rows for assignment to SObject' which I have tried to look up but there are so many answers and they don't apply to my certain case. Tried it multiple ways and I am wondering if anybody here has a good answer.

  8. Common fix to a "Error: List has no rows for assignment to SObject

    Error when rejecting Applications: List has no rows for assignment to SObject Applications (and the other AMS Stages) has a Master-Detail Object Relationship within ...

  9. System.QueryException: List has no rows for assignment to SObject. How

    The class being tested is expecting an Id, but your test is not passing an Id. The issue is on the last line of code in your test class: ItemSetupNewVersionController.itemSetupClone('is.ParentId__c'); enclosing things in single quotes makes it a string, so you're literally passing "is.ParentId__c" to the method you're testing (instead of the id of the record).

  10. Salesforce Error: List has no rows for assignment to SObject

    Error: List has no rows for assignment to SObject. Error: User unable to update ... Permission Denied. Please check your Field Level Security settings. These errors can occur for iContact for Salesforce Users that do not have Read Access for iContact Custom Fields.

  11. Help with error: List has no rows for assignment to SObject

    Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site

  12. Can somebody explain the error 'System.QueryException: List has no rows

    There are no longer humans in the known universe. It describes meeting one of the last humans Results of invertibility of a matrix involving the Szego kernel

  13. Document Generation Error- "List has no rows for assignment to SObject

    General Information. We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply.

  14. Vague "List has No Rows for Assignment to SObject" Error

    List<sObject> // [SELECT Id FROM Contact LIMIT 100] (returns a list of 100 Contacts) sObject // [SELECT Id FROM Contact LIMIT 1] (returns a single Contact) Integer // [SELECT Count() FROM Contact] (returns how many Contacts exist in your org) There is a gotcha here, that you ran up against.

  15. CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: execution of AfterInsert

    First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PriceBookEntryUpdate: execution of AfterInsert caused by: System.QueryException: List has no rows for assignment to SObject Trigger.PriceBookEntryUpdate: line 42, column 1: [] 15:26:23.553 (9553859000)|FATAL_ERROR|System.DmlException: Insert failed.

  16. Docusign Custom Button Error: List has no rows for assignment to SObject

    Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.Provide details and share your research! But avoid …. Asking for help, clarification, or responding to other answers.