• Stack Overflow Public questions & answers
  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Talent Build your employer brand
  • Advertising Reach developers & technologists worldwide
  • About the company

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.

List has no rows for assignment to SObject error although query returns rows

I'm a bit new to apex and I am trying to display a selectList in a visualforce page using a custom controller i built.

I get a "List has no rows for assignment to SObject" error when trying to preview the visualforce page, but running the query in the developer console, returns the rows.

here is my page:

and my controller:

Just to clarify the query i'm referring to is the query in getProductsLov() .

My API version is 40 and i am working in a sandbox environment.

RealGigex's user avatar

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

You're viewing the page with valid Account Id passed in the URL? And that Account is visible for your current user? If the page is account-specific, try using <apex:page standardController="Account" extensions="BpmIcountPayment">... (you'll have to provide a different constructor in apex first). This could simplify your code a lot.

eyescream's user avatar

Your Answer

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 , privacy policy and cookie policy

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

Hot Network Questions

list has no rows for assignment to sobject class

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .

Stack Exchange Network

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

Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.

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 in a test class

I need to create a test class for the below mentioned class so far I am getting the error "List has no rows for assignment ".Here customer address is an object whose parent is contact

Rohit Mourya's user avatar

Since Contact is parent for Customer_Address__c Object, there might be case that one Contact can have multiple Customer_Address__c Object.

So replace this line:

Also in your test class you're not creating customer_address__c data. That's why you're getting that error. Add below lines after inserting contact in your test class:

Your Answer

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 , privacy policy and cookie policy

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

Hot Network Questions

list has no rows for assignment to sobject class

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .

list has no rows for assignment to sobject class

list has no rows for assignment to sobject class

Don't have an account?

Browse by Topic

Welcome to Support!

Search for an answer or ask a question of the zone or Customer Support.

You need to sign in to do that

Sign in to start searching questions

Signup for a Developer Edition

Sign in to start a discussion

Laaral

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

Hi , I'm getting this error message : System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, SetupChangeTechnologyListCheck: execution of AfterInsert caused by System.QueryException: List has no rows for assignment to SObject: : line 8, column 1

I don't understand why it doesn't find account objects, because there are alot of them in SF ?  Where should I start looking for an answer to this? Many thanks already, if you could somehow help me understand this better.

trigger SetupChangeTechnologyListCheck on Setup__c (after insert, after update) {     for(Setup__c s : trigger.new)     {                  Account acc = [SELECT Name, Service_Type_List__c FROM Account WHERE RecordType.Name = 'Main Account' AND Name = :s.Main_Account__c];                          UpdateMainAccountTechnologyList techList = new UpdateMainAccountTechnologyList();         techList.UpdateList(acc);                      } }

hitesh90

The exception is because of you are not getting any record in your SOQL query..

which meet the where criteria so it's give error.

Important : Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits. Thank You, Hitesh Patel SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant My Blog:- http://mrjavascript.blogspot.in/

All Answers

Rosh

 Its always a best practice to check if list is not empty before doing any DML operation.

Your code could be modified tso that it doen't throw an exception:

trigger SetupChangeTechnologyListCheck on Setup__c (after insert, after update) {

for(Setup__c s : trigger.new) { list<Account> accountList = [SELECT Name, Service_Type_List__c FROM Account WHERE RecordType.Name = 'Main Account' AND Name = :s.Main_Account__c]; Account acc = (accountList != null && accountList.size()>1) ? (accountList[0] : null; if (acc != null) { UpdateMainAccountTechnologyList techList = new UpdateMainAccountTechnologyList(); techList.UpdateList(acc); } } }

Dmytro Kurylo

You need to sign in to do that.

Select a category.

IMAGES

  1. apex

    list has no rows for assignment to sobject class

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

    list has no rows for assignment to sobject class

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

    list has no rows for assignment to sobject class

  4. Salesforce: Testing page for entry

    list has no rows for assignment to sobject class

  5. Salesforce Development : r/SalesforceDeveloper

    list has no rows for assignment to sobject class

  6. 【Apex】List has no rows for assignment to SObjectのエラーと解決策について

    list has no rows for assignment to sobject class

VIDEO

  1. Sangatkar

  2. My Absolute Final BTNL (Part 5)

  3. Ch 8 Part 3 Passing a List

  4. Week 11-Lesson 4:Multiple columns

  5. Apex Legends #apexclips #apexlegendsps #apexmemes #ps #apex #games #pc #apexlegends

  6. Row Vs Column Oriented Databases

COMMENTS

  1. List has no rows for assignment to SObject - Test Class

    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 Mar 28, 2016 at 20:42

  2. custom object - List has no rows for assignment to SObject ...

    The list (the result of your select) is not returning any rows, which means the assignment to your SObject m is failing. Make sure that the query is correct. Is the parameter you use in the query being set on the page? Is there data that fulfils the criteria? Also consider adding some Apex Pagemessage error elements. Share Improve this answer

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

  4. List has no rows for assignment to SObject error although ...

    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. List has no rows for assignment to SObject in a test class

    1 Answer. Sorted by: 1. Since Contact is parent for Customer_Address__c Object, there might be case that one Contact can have multiple Customer_Address__c Object. So replace this line: Customer_Address__c customerAddress= [SELECT ID,Customer__c,Customer_Address_ID__c FROM Customer_Address__c WHERE Customer__c =:contact.Id ]; With: List<Customer ...

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

    First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, SetupChangeTechnologyListCheck: execution of AfterInsert caused by System.QueryException: List has no rows for assignment to SObject: : line 8, column 1 I don't understand why it doesn't find account objects, because there are alot of them in SF ?

  7. Error ‘List has no rows for assignment to SObject’ in ...

    Resolution The error 'List has no rows for assignment to SObject' occurs when an invalid quote process ID exists on the Quote's Quote Process ID field. This field is meant to be populated by a workflow rule. This issue can also occur when the user attempts to reconfigure a Primary Quote without Read access to the associated Opportunity.

  8. Salesforce: List has no rows for assignment to SObject - Test ...

    Salesforce: List has no rows for assignment to SObject - Test ClassHelpful? Please support me on Patreon: https://www.patreon.com/roelvandepaarWith thanks &...