function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

List has no rows for assignment to SObject


After moving from QA to PROD , i m able to acces all the feild in few Oppprtunity Owners not for all.

For example i have a Opportunity say (opportunity owner =A) i am able to get  all fields when i change the same Opportunity  to (opportunity owner =B) i get
 ( List has no rows for assignment to SObject) Error message can any one help me out.

Thanks in Advance.
Ankit AroraAnkit Arora
Tyr running you Apex classes in whitout sharing mode and let me know.
Hi Ankit Arora

With & WItho out Sharing I m Getting same error.
Phillip SouthernPhillip Southern
Ishak, check your security OWD for opportunties and sharing rules to ensure when owner B has opportunities then your context user can access it.

This error occurs when query doesn't return any rows.

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!

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

Player__c player = [SELECT Id from Player__c where Name = :username];
if (player != null)
p = player.Id;

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:

Player__c[] players = [SELECT Id from Player__c where Name = :username];
if (players.size() > 0)
p = players[0].Id;

However, in your case, I believe there is a permission issue.Please cheeck all the permission properly.