+ Start a Discussion
karthic sankar 9karthic sankar 9 

Please help me in debugging below SOQL

Kindly let me what mistake I am making in below SOQL?

select Week__c from cutomobject where OwnerId = userinfo.getUserId()

select Week__c, max(createddate),max(Name) Submittername from cutomObject where OwnerId = :userinfo.getUserId() group by Week__c order by max(createddate) desc LIMIT 10
SwethaSwetha (Salesforce Developers) 
HI Karthic,
Are you seeing any error message?
Sangeet kaseraSangeet kasera
Hi Karthic,

If you are using your first query in Apex class then there is one mistake in your query change accordingly-
Correct query is -
Integer totalRecords =  [select COUNT() FROM cutomobject Where OwnerId =: UserInfo.getUserId()];

This Will give you the total number of record in custom object.

And for your second query simple way if you are getting any error-
Store userinfo.getUserId() in one variable then add it in query like below

String userDetail = UserInfo.getUserId();

Query-
select Week__c, max(createddate), max(Name), Submittername from cutomObject where OwnerId = :userDetail group by Week__c order by max(createddate) desc LIMIT 10

Also may be  comma is missing before Submittername field in you query, if it is custom field.

Regards,
Sangeet


 
Sangeet kaseraSangeet kasera
Hi Karthic,

Will you please choose answer as best, If you found that my answer is relevant for you.
Which helps for other.

Regards,
Sangeet