+ Start a Discussion
:) :) :) :) :):) :) :) :) :) 

Return type of [select count() from sObject where Condition ]

Hi guys I am trying to counting total rows in opportunity object using count() but its giving me an errors says  Compile Error: Illegal assignment from LIST<SObject> to Integer at line 95 column 11

 


let me show you what I am doing.

 

String soql = 'select count() from lead where Ownerid=:18digit_id and IsConverted=false';

 

Integer leadCount = Database.query(soql);  // Getting error here.

 

Any One had a problem before?

 

Thanks guys

 

Best Answer chosen by Admin (Salesforce Developers) 
Starz26Starz26

I messed that up between the copy and paste:

 

try

 

String soql = 'select count() from lead where Ownerid=:18digit_id and IsConverted=false';

 

Integer leadCount = Database.countQuery(soql);

All Answers

Starz26Starz26

Use countQuery

 

 

see below

:) :) :) :) :):) :) :) :) :)

Its not solving my error. let me know if you have another solution. still its giving me same error.

Starz26Starz26

I messed that up between the copy and paste:

 

try

 

String soql = 'select count() from lead where Ownerid=:18digit_id and IsConverted=false';

 

Integer leadCount = Database.countQuery(soql);

This was selected as the best answer
:) :) :) :) :):) :) :) :) :)

I got my answer now. but in Dynamic SOQL we can not bind nested fields some how. I don't know why but we can not. 

 

String soql = 'select count() from lead where Ownerid=:18digit_id and IsConverted=false';

 

Integer leadCount = Database.countQuery(soql);  // Getting error here. 

 

instead of that if I write

 

Integer leadCount = [select count() from lead where Ownerid=:18digit_id and IsConverted=false]; // working fine no error.

 

its working perfactly fine but dynamic soql giving me an error. 

 

http://boards.developerforce.com/t5/Apex-Code-Development/Dynamic-SOQL-cannot-bind-to-nested-fields/m-p/180720#M28780

 

any body knows how can we deal with dynmaic soql ?

 

 

 

:) :) :) :) :):) :) :) :) :)

Thanks I got my answer with your help !! But we only can count 50,000 right? Or Can we bypass governor limit here.