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
JaanuJaanu 

soql question

SELECT CaseNumber, Case_State__c, Priority, Status, Case_Sub_Status__c FROM Case WHERE Status != 'Complete' AND OwnerId=:UserInfo.getUsername()

Unknown error is coming for the above one .. I am trying to get all the open cases for the user who is running this stmt. 
Best Answer chosen by Jaanu
Raj VakatiRaj Vakati
You need to use the owner Id equals to UserInfo.getUserId() 
SELECT CaseNumber, Case_State__c, Priority, Status, Case_Sub_Status__c FROM Case WHERE Status != 'Complete' AND OwnerId=:UserInfo.getUserId()

OR

TRY this one if you wanted to do with OWNERNAME

 
SELECT CaseNumber, Case_State__c, Priority, Status, Case_Sub_Status__c FROM Case WHERE Status != 'Complete' AND Owner.Name=:UserInfo.getUsername()



 

All Answers

v varaprasadv varaprasad
Hi Jaanu,

Try once below code : 

 
SELECT CaseNumber, Case_State__c, Priority, Status, Case_Sub_Status__c FROM Case WHERE Status != 'Complete' AND OwnerId=:UserInfo.getUserId()

Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.

Thanks
Varaprasad
@For  Support: varaprasad4sfdc@gmail.com
Blog : http://salesforceprasad.blogspot.com/
 
Raj VakatiRaj Vakati
You need to use the owner Id equals to UserInfo.getUserId() 
SELECT CaseNumber, Case_State__c, Priority, Status, Case_Sub_Status__c FROM Case WHERE Status != 'Complete' AND OwnerId=:UserInfo.getUserId()

OR

TRY this one if you wanted to do with OWNERNAME

 
SELECT CaseNumber, Case_State__c, Priority, Status, Case_Sub_Status__c FROM Case WHERE Status != 'Complete' AND Owner.Name=:UserInfo.getUsername()



 
This was selected as the best answer
JaanuJaanu
great.. thanks