in below query it'll throw an exception unknown token )
what the issue for this OwnerId= :UserInfo.getUserID()

  SELECT  Status, Origin from Case WHERE OwnerId= :UserInfo.getUserID() And Status != '\open\'';
  • In case if that is dynamic soql -- apex statements are not executed. Please, execute UserInfo.getUserId() before, assign to variable and insert it in body of SOQL query – kurunve Apr 18 '17 at 16:20

Better to use bind variable in SOQL.

String str = 'open';

List<Case> caseList = [SELECT  Status, Origin from Case 
WHERE OwnerId=:UserInfo.getUserID() 
And Status !=:str];

For dynamic query use like this:

String str = 'open';
String userId = UserInfo.getUserID();
String queryStr = 'SELECT  Status, Origin from Case WHERE OwnerId=:userId And Status !=:str';
List<Case> caseList = Database.query(queryStr);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.