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.

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

execution of BeforeInsert caused by: System.QueryException: List has no rows for assignment to SObject

I have a trigger in place for Opportunity. This trigger is meant to fire when an opportunity reaches the 'VoB Pending' stage.

The only time it fails is when I create an opportunity and set the stage to 'VoB Pending', soon as i hit the create button (Save), i get the folowing error.

opportunityOwnerAlert: execution of BeforeInsert caused by: System.QueryException: List has no rows for assignment to SObject Class.lightningStep.Sendtest: line 10, column 1 Trigger.opportunityOwnerAlert: line 12, column 1

line 10 is just a soql query,

Im a little lost as to why its not being picked up by the trigger since i have the 'before insert' on the trigger. Any help is appreciated.

  • before-trigger
  • triggercontext
  • queryexception

potato46's user avatar

The Id of a SObject is not available in BeforeInsert context. As this is running before the records are there in database.

Hence firing this

[SELECT Id FROM Opportunity WHERE Id = : oppIds LIMIT 1];

will return an empty List and when you try to store the return value into Opportunity opp , Salesforce tries to internally fetch the first item from list and store it in opp .

But as list is empty, hence you see an exception List has no rows for assignment to SObject

I am not aware of full use case, but you can try shifting your context to AfterInsert .

BTW, why to just query Id again, if you already have an Id from the trigger.

Nagendra Singh's user avatar

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged apex trigger before-trigger triggercontext queryexception ..

  • Featured on Meta
  • Announcing a change to the data-dump process
  • Upcoming initiatives on Stack Overflow and across the Stack Exchange network...

Hot Network Questions

  • Why would these two populations be genetically compatible?
  • All QFTs are Finite
  • Can I abort some of the attacks in a full attack action?
  • Submitting paper to lower tier journal instead of doing major revision at higher tier journal
  • 7x10 floor and a 8x8 and a 6x1 carpet, only one cut allowed
  • AttributeError: 'QuantumCircuit' object has no attribute 'ucry'. Did you mean: 'cry'?
  • Indent format of algorithm2e in revtex4-1
  • Tic Tac Toe with only the 3 last moves
  • Should the page object model return a new page object model when navigating to another page?
  • Relationship between Pythagorean Triples and double/half angles
  • Given 3 points on a twisted edward curve, if I know 2 discrete logarithms, is it possible compute the third relation/discrete logarithm?
  • gwenview pass file names from es.exe command line to everything voidtools
  • The vertiginous question: Why am I me and not someone else?
  • English equivalent for the idiom "mother-in-law has forgotten to wear her saree (dress)"
  • Extending Implicit Function Theorem to Show Global Existence
  • Why did Kamala Harris once describe her own appearance at the start of an important meeting?
  • Tale of two servers. What could be limiting queries to running on two cores? MDOP set to 16
  • What does *qui* mean in a non-defining relative clause?
  • Publishing a paper written in your free time as an unaffiliated author when you are affiliated
  • How do I drop a database which has brackets in its name?
  • What are applicable skills and abilities for dealing with paperwork, administration and law in 5e?
  • What does "joint-most" exactly mean?
  • Can a "read-only" µSD card be salvaged?
  • Display attribute table with specified decimals

no rows for assignment to sobject

Get the Reddit app

This is an unofficial (no salesforce sponsorship) forum to discuss getting certified and building on salesforce platforms (force.com, heroku, exacttarget, slack, etc.)

DocuSign custom button error, "List has no rows for assignment to SObject"

I'm trying to create a button that will automatically send a specific DocuSign document to the applicant. I'm going off of the sample javascript they provide in the DocuSign for Salesforce, Administrator Guide . When I try to click the button I receive an error message that says, " List has no rows for assignment to SObject ".

The Applicant's name is stored as a custom field, Opportunity.Applicant_c (lookup), FirstName as Opportunity.First_Name_c, and the email is Opportunity.Email_c (those actually have the standard two underscores, but reddit makes double underscores bold, so I erased one). The contact is also stored as a Contact Role with the role value as "Applicant". I keep trying to change different variables, but I'm going in circles at this point. Seems like it should be really easy, right? Help me please before I lose my mind

By continuing, you agree to our User Agreement and acknowledge that you understand the Privacy Policy .

Enter the 6-digit code from your authenticator app

You’ve set up two-factor authentication for this account.

Enter a 6-digit backup code

Create your username and password.

Reddit is anonymous, so your username is what you’ll go by here. Choose wisely—because once you get a name, you can’t change it.

Reset your password

Enter your email address or username and we’ll send you a link to reset your password

Check your inbox

An email with a link to reset your password was sent to the email address associated with your account

Choose a Reddit account to continue

  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand
  • OverflowAI GenAI features for Teams
  • OverflowAPI Train & fine-tune LLMs
  • Labs The future of collective knowledge sharing
  • About the company Visit the blog

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Get early access and see previews of new features.

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

Custom button code:

Visualforce error:

I have checked the permissions suggested by docusign and nothing has changed.

Any advice/help would be HUGELY appreciated!

  • docusignapi

Stacey's user avatar

  • How about formatting your code to make it a little easier to read? –  Andre Perkins Commented Oct 30, 2014 at 15:10

2 Answers 2

The script is failing because DocuSign envelope Id has been set to 961202FA-36C6-4A9A-B061-EDC7BE6C8B07. The DSIED should be set to ‘0’ by default. Set DSIED=0 and the script should work:

Ergin's user avatar

If you set the DSEID=0 then it does not populate the template with the Client data which is what we are trying to do. How do you get the Sign Now custom button to work.

Francois's user avatar

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Sign up or log in

Post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .

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

  • Featured on Meta
  • Upcoming initiatives on Stack Overflow and across the Stack Exchange network...
  • Announcing a change to the data-dump process

Hot Network Questions

  • Travelling from Ireland to Northern Ireland (UK Visa required national)
  • The vertiginous question: Why am I me and not someone else?
  • Submitting paper to lower tier journal instead of doing major revision at higher tier journal
  • Can Victorian engineers build spacecraft with an Epstein drive?
  • Is this sample LSAT question / answer based in fallacy?
  • Differential vs. Single-Ended amplification for sensor sampling
  • Are strict higher categories more general than weak higher categories?
  • A seemingly pointless puzzle
  • Transporting an inflatable SUP by train and bike, while being able to look over my shoulder
  • How to calculate baker's percentages for indirect doughs?
  • Former manager and team keep reaching out with questions despite transferring to a new team
  • N-MOS failing short on my PCB
  • Why does the 68000 have Immediate addressing modes for .b instructions?
  • Why exactly do we need the learning rate in gradient descent?
  • Why is Epsilon Indi Ab 2° Celsius?
  • Canola and dishwasher
  • Can I abort some of the attacks in a full attack action?
  • When I attach a sensitive pdf encrypted by Adobe with a password, and send it through Gmail with password included, does it make any difference?
  • Source for a day for Hashem equaling 1,000 years for us
  • Does this follow from Everett's Many-Worlds?
  • Indent format of algorithm2e in revtex4-1
  • Why is transpose not equal to inverse in general?
  • Securing Transactional Email: User Input Escaping for a email subject
  • Should we use subject auxiliary verb order in 'what a better day could there be to go to one of the local farmers markets!'?

no rows for assignment to sobject

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. Understanding 'List has no rows for assignment to SObject' in a trigger

    no rows for assignment to sobject

  4. System.QueryException: List has no rows for assignment to SObject for Object created in test case

    no rows for assignment to sobject

  5. Salesforce: List has no rows for assignment to SObject test class

    no rows for assignment to sobject

  6. Salesforce: Test Class

    no rows for assignment to sobject

VIDEO

  1. Session 4 SObject DataTypes Variables mp4

  2. SSIS

  3. i sadly saw no rows of tractors with an endless amount of dudes on em like in the memes 😭 #memes

  4. #56 What are sObject in Salesforce?

  5. Convert String to sObject using Apex in Salesforce

  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. Error 'List has no rows for assignment to SObject' in Salesforce CPQ

    This issue can also occur when the user attempts to reconfigure a Primary Quote without Read access to the associated Opportunity. Lack of access to the Opportunity object throws List has no rows for assignment to SObject' since our code queries for the Primary Quote on that opportunity.

  7. 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:

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

    Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.

  9. 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.

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

    Common fix to a "Error: List has no rows for assignment to SObject" error received when Rejecting Applications.

  11. 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.

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

    List has no rows for assignment to SObject errors Hot Network Questions How widely is "where failure could result in death, injury, or damage" interpreted?

  13. "List has no rows for assignment to SObject"

    Adjust Contact Settings. Go to Setup > Customize > Contacts > Record types. Check the active checkbox for Candidates.

  14. 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.

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

    Svelte is a radical new approach to building user interfaces. Whereas traditional frameworks like React and Vue do the bulk of their work in the browser, Svelte shifts that work into a compile step that happens when you build your app.

  16. execution of BeforeInsert caused by: System.QueryException: List has no

    But as list is empty, hence you see an exception List has no rows for assignment to SObject. I am not aware of full use case, but you can try shifting your context to AfterInsert. BTW, why to just query Id again, if you already have an Id from the trigger.

  17. DocuSign custom button error, "List has no rows for assignment to SObject"

    This is an unofficial (no salesforce sponsorship) forum to discuss getting certified and building on salesforce platforms (force.com, heroku, exacttarget, slack, etc.) ... "List has no rows for assignment to SObject". The Applicant's name is stored as a custom field, Opportunity.Applicant_c (lookup), FirstName as Opportunity.First_Name_c, and ...

  18. CLM-Document Generation Error- "List has no rows for assignment to

    Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.

  19. 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.