0

I have an issue with SOQL in apex. I try to get cases with Status equal to New. Problem is about telling apex in SOQL to choose New cases. I tried it this

public class NewCaseListController {

public List<Case> getNewCases(){
    List<Case> result=Database.query(
    'SELECT Id, CaseNumber '+
    'FROM Case WHERE Status="New"');
        return result;

}

}

and this way

public class NewCaseListController {

public List<Case> getNewCases(){
    List<Case> result=Database.query(
    'SELECT Id, CaseNumber '+
    'FROM Case WHERE Status=New');
        return result;

}

}

, but both finished unsuccessfully. Could you help me to put this value inside correctly?

2

One problem with your queries is that you've used " in one and nothing in another. You need to use apostrophes or '. The easiest way to do this is to escape the apostrophies wrapping "new". You can do this by preceeding those apostrophies with a slash. So, your query will look like this:

'SELECT Id, CaseNumber FROM Case WHERE Status=\'New\''

Salesforce will ignore anything directly proceeding the \.

| improve this answer | |
1

Or you could do:

List<Case> result = new List<Case>([SELECT Id, CaseNumber FROM Case WHERE Status = 'New']);
| improve this answer | |

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.