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.

Logo

Scheduled Maintenance Notification: Soapbox Engage will be performing scheduled maintenance on Saturday, August 31, 2024 from 6 am - 10 am ET. Learn More >>

MAJOR APP UPDATE WEBINAR: Successful Ecommerce with the Soapbox Engage Shop app , Wednesday, 1/27/2021, 3 - 3:45PM ET Register >>

FEATURED WEBINAR RECORDING: Virtual Events with Zoom and the Soapbox Engage Events app Watch >>

We're hiring! Join us in helping nonprofits raise more money and change the world. Learn more >>

Why do I see a "List has no rows for assignment to SObject" error after attempting to create a Salesforce Opportunity record?

Ryan Ozimek on--> updated December 06, 2023 17:48

After a Salesforce user attempts to create a new Opportunity record, they might see part of the following error.

Potential Solution

If your organization is using the Soapbox Events for Salesforce connector app (a managed package), this issue tends to be related to missing record types on the Opportunity and Lead objects.  As a starting point, ensure that the following record types are included.

  • Opportunity object:  Soapbox Registration Order
  • Lead object:  Soapbox Registration Order

If either of these record types are missing from your Salesforce org, you'll want to create them manually following the steps.

IMPORTANT NOTE :  These are different and separate record types from the "Soapbox Registration" record types on the Lead and Opportunity objects.

Go to Setup > Object Manager> Leads > Record Types

Click the New button to create a new record type

For Existing Record Type, leave it selected for “--Master--”

For Record Type Label, enter “Soapbox Registration Order”.

  • For Sales Process = “Soapbox Events Registrations"

For Record Type Name, enter “sbx_Registration_Order_Lead”.

For Lead Process, choose “Default” or whatever the name of your default lead process might be.

For Description, enter “Soapbox Events registration order Lead record type.”

For Active, check the checkbox.

At the bottom of the screen, choose which profiles should have access to this Default record type. Most times, you can likely check all of the Enable for Profile boxes, but if you need to limit it, at least enable it for the System Administrator. Additionally, if you’d like to continue to make this the default record type chosen for the object when using Salesforce, check the appropriate Make Default boxes.

Click the Next button.

Select the “Apply one layout to all profiles” option, and in the dropdown to the right of it, choose the “Lead Layout”. This will make this make the new Default record type’s default layout the original Lead Layout. You can also customize this as you wish.

Click the Save button.

Go to Setup > Object Manager> Opportunities > Record Types

For Record Type Name, enter “sbx_Registration_Order_Opportunity”.

For Opportunity Process, choose “Default” or whatever the name of your default sales process might be.

For Description, enter “Soapbox Events registration order Opportunity record type.”

Select the “Apply one layout to all profiles” option, and in the dropdown to the right of it, choose the “Opportunity Layout”. This will make this make the new Default record type’s default layout the original Opportunity Layout. You can also customize this as you wish.

list has no rows for assignment to sobject

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.

List has no rows for assignment to SObject: ERROR APEX

im trying to validate a new outbound set into production but still get following error code:

List has no rows for assignment to SObject

for this code:

We never changed this apex class. But im trying to validate a new outbound set to salesforce and i keep getting this error code. I want to validate the new outbound set, I get the error message for this apex class, although it has nothing to do with the actual outbound set.

many thanks in advance

  • administration

Jeferson Chaves's user avatar

This error msg means that query did not return any results, and you are trying to assign this to SObject. It could be either this line

Or somewhere else in the TestDataGenerator.createAccount(true) .

When you are deploying a change set, you can choose to run just a specified test, and then quick deploy the change. This way, salesforce won't validate the change set with other apex test.

Damecek's user avatar

  • I changed the error line into this : List<profile> p = [select id from Profile where Name = 'System Administrator' limit 1]; Now i got 9 new problems :D Any chance you could have a look to my apex class ? –  Sanjar Jurhat Commented Oct 8, 2021 at 13:41

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged apex error administration ..

  • The Overflow Blog
  • One of the best ways to get value for AI coding tools: generating tests
  • The world’s largest open-source business has plans for enhancing LLMs
  • Featured on Meta
  • User activation: Learnings and opportunities
  • Site maintenance - Mon, Sept 16 2024, 21:00 UTC to Tue, Sept 17 2024, 2:00...

Hot Network Questions

  • Minimum of a continuous function on the interior of the unit ball
  • What prevents indoor climbing gyms from making a v18 boulder even if one hasn't been found outside?
  • Equation of Time (derivation Analemma)
  • What would the natural diet of Bigfoot be?
  • How is switching of measurement ranges in instruments, like oscilloscopes, realized nowadays?
  • What is the origin of 找碴?
  • How should I email HR after an unpleasant / offensive interview?
  • Why is steaming food faster than boiling it?
  • How to deal with coauthors who just do a lot of unnecessary work and exploration to be seen as hard-working and grab authorship?
  • Basic question - will "universal" SMPS work at any voltage in the range, even DC?
  • How to avoid bringing paper silverfish home from a vacation place?
  • How to prove that the Greek cross tiles the plane?
  • How can I send instance attributes from Geometry Nodes to Shading Editor?
  • Why was Panama Railroad in poor condition when US decided to build Panama Canal in 1904?
  • What would be an appropriate translation of Solitude?
  • Copyright Fair Use: Is using the phrase "Courtesy of" legally acceptable when no permission has been given?
  • What are the pros and cons of the classic portfolio by Wealthfront?
  • How can a microcontroller (such as an Arduino Uno) that requires 7-21V input voltage be powered via USB-B which can only run 5V?
  • If Act A repeals another Act B, and Act A is repealed, what happens to the Act B?
  • Can I repeat link labels several times on a web page without hurting SEO by using meta attributes?
  • cat file contents to clipboard over ssh and across different OS
  • Is it feasible to create an online platform to effectively teach college-level math (abstract algebra, real analysis, etc.)?
  • Is there a fundamental difference between Chinese and Taiwanese slang/profane?
  • How to apply a squared operator to a function?

list has no rows for assignment to sobject

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

  • The Overflow Blog
  • One of the best ways to get value for AI coding tools: generating tests
  • The world’s largest open-source business has plans for enhancing LLMs
  • Featured on Meta
  • User activation: Learnings and opportunities
  • Site maintenance - Mon, Sept 16 2024, 21:00 UTC to Tue, Sept 17 2024, 2:00...
  • What does a new user need in a homepage experience on Stack Overflow?
  • Announcing the new Staging Ground Reviewer Stats Widget

Hot Network Questions

  • Is it safe to use the dnd 3.5 skill system in pathfinder 1e?
  • Why did early ASCII have ← and ↑ but not ↓ or →?
  • Definition of annuity
  • Why do I often see bunches of medical helicopters hovering in clusters in various locations
  • How to expand argument in the Expl3 command \str_if_eq?
  • How many engineers/scientists believed that human flight was imminent as of the late 19th/early 20th century?
  • Drill perpendicular hole through thick lumber using handheld drill
  • What is the origin of 找碴?
  • How do you ensure that calendar invites won't be moved out of your inbox when your rules are executed?
  • Connections vertically and horizontally
  • The consequence of a good letter of recommendation when things do not work out
  • grouping for stdout
  • Why are some Cloudflare challenges CPU intensive?
  • Basic question - will "universal" SMPS work at any voltage in the range, even DC?
  • Concerns with newly installed floor tile
  • O(nloglogn) Sorting Algorithm?
  • What is the rationale behind 32333 "Technic Pin Connector Block 1 x 5 x 3"?
  • Is it true that before European modernity, there were no "nations"?
  • Look for mistakes!
  • Why was Panama Railroad in poor condition when US decided to build Panama Canal in 1904?
  • How to apply a squared operator to a function?
  • 4/4 time change to 6/8 time
  • The meaning of an implication in an existential quantifier
  • How did people know that the war against the mimics was over?

list has no rows for assignment to sobject

IMAGES

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

    list has no rows for assignment to sobject

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

    list has no rows for assignment to sobject

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

    list has no rows for assignment to sobject

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

    list has no rows for assignment to sobject

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

    list has no rows for assignment to sobject

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

    list has no rows for assignment to sobject

VIDEO

  1. MUph2024 TOP 5 STANDOUTS during the PRELIMINARY INTERVIEW!

  2. "Life has No Value if it's Measured Only in Money"

  3. TOP 4 OTS [March 2024]: Sky Striker Deck Profile (Yu-Gi-Oh TCG)

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

  5. YouTube Fix History This list has no videos Problem Solve

  6. Listing columns using sys.columns, and creating a SELECT statement JOINing three tables

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

    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.

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

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

  5. Apex error

    Learn how to fix the error that occurs when query doesn't return any rows in Apex code. See the cause, resolution and example of the shorthand syntax that assumes only one row is returned.

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

    Facing the 'List has no rows for assignment to SObject' error in Salesforce? In this video, I'll explain what this error means, why it occurs, and how you ca...

  7. List has no rows for assignment to SObject

    List has no rows for assignment to SObject. Potential Solution. If your organization is using the Soapbox Events for Salesforce connector app (a managed package), this issue tends to be related to missing record types on the Opportunity and Lead objects. As a starting point, ensure that the following record types are included.

  8. Salesforce: System.QueryException: List has no rows for assignment to

    Learn why the error "System.QueryException: List has no rows for assignment to SObject" occurs and how to fix it. See an example of using a List variable to check the query results before assigning them to an SObject.

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

    Learn how to resolve the "Error: List has no rows for assignment to SObject" error when rejecting applications in Bullhorn AMS. The error occurs when the record types of the application and the job order do not match.

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

    Learn how to fix the error "List has no rows for assignment to SObject" when generating documents with Docgen Document Template Library. The error occurs due to insufficient access to the document template or custom fields marked as required.

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

    First, the 'account' instance must be initialised. Second, just make sure the ID is being passed in the page's URL correctly. In the ApexPages.currentPage ().getParameters ().get ('id') statement, the .get ('id') part is case sensitive. So please make sure, that is how you have passed your ID in the URL. Third, there should be a record in ur ...

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

    It's a very common mistake to see client devs not do this, and it can lead to serious issues on big orgs. Writing code this way usually lowers C1 complexity, which makes unit tests a lot easier. Having one record gets you 100% coverage and doesn't throw exceptions or have multiple exits.

  13. testing

    Here is what i tried. I think the problem is somewhere in the test class when i create the apex test controller and i want to link the record of the controller to the solution that i created in ...

  14. List has no rows for assignment to SObject: ERROR APEX

    'List has no rows for assignment to SObject' Mystery. 0. SObject List holding IDs. 0. Apex Testing Error: System.QueryException: List has no rows for assignment to SObject. Hot Network Questions Why is a USB memory stick getting hotter when connected to USB-3 (compared to USB-2)?

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