+ Start a Discussion
ifthikar Ahmed 1ifthikar Ahmed 1 

can a soql query return Boolean and string value ?

can a soql query return Boolean and string value ?
lnallurilnalluri
SOQL/SOSL returns List<Sobjects>

Not sure what is your use case but the below is possible.
 
String firstName=[SELECT Id,FirstName FROM User LIMIT 1].FirstName;

Boolean isActive=[SELECT Id,isActive FROM User LIMIT 1].isActive;

 
ifthikar Ahmed 1ifthikar Ahmed 1
@Inalluri
i was bit confused by the below question

User-added image
ifthikar Ahmed 1ifthikar Ahmed 1
@Inalluri

also can you pls explain the concept of your above example ' where you have added .FirstName after the query String firstName=[SELECT Id,FirstName FROM User LIMIT 1].FirstName; '
Deepali KulshresthaDeepali Kulshrestha
Hi ifthikar, 

You can return also return a singe sObject from a SOQL.
Also the Example used by @lnalluri 
The query he used will return a record from User and putting .name at the end will return FirstName From the query which is stored in the String firstname. 
Let me tell by giving another example.

Suppose we have a sObject which have the folollowing fields and datatype.

sObject Name ---> Account

Field Name                    Datatype
Name                      String
Number of Employees             Number
isActive                 Boolean

So if i want my query to return Integer then ill use .NumberofEmployees at the end of my query which is a number field.

Integer num = [SELECT ID, NumberOfEmployees FROM Account LIMIT 1].NumberOfEmployees];

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
Ajay K DubediAjay K Dubedi
Hi Ifthikar,

I have gone through your query and inspected your question too.
You can return all three types of datatype i.e Boolean, String, Integer from a SOQL query.
The correct options for the question are-
A, C and D

(A) - Boolean

(B) - String

(c) - Integer


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com