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
ledap13ledap13 

problem with my SOQL query

Hi friends,
I have a problem with my SOQL query.
Why can I not query the AccountId like this?

public Id idAcc {get;set;}
            .
            .
idAcc = [SELECT AccountId FROM Opportunity WHERE ID = :quo.OpportunityId LIMIT 1];



But with the following string is correct

Opportunity Opp = [SELECT AccountId FROM Opportunity WHERE ID = :quo.OpportunityId LIMIT 1];
Best Answer chosen by ledap13
Chidambar ReddyChidambar Reddy
Hi,
Since SOQL returns list of SObjects. You can't assign List to a variable.

You can put egg(s) in the egg tray, but not the omlet.

You can get the Id like below.


public Id idAcc {get;set;}
            .
            .
idAcc = [SELECT AccountId FROM Opportunity WHERE ID = :quo.OpportunityId LIMIT 1].AccountId ;


Append .AccountId at the end of SOQL.


which is similar to

Opportunity Opp = [SELECT AccountId FROM Opportunity WHERE ID = :quo.OpportunityId LIMIT 1];
idAcc = Opp.AccountId;



Thankyou
You can choose it as best answer, if it answered your question.