0

Im doing the Create & Use Custom Controllers from trailhead on module visual force basics, I do not know what to do but i have an error in my where clause

    //This is my controller

public class NewCaseListController {
    private String tipoCaso = 'New';

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

}

And my view


<apex:page controller="NewCaseListController" >
    <apex:pageBlock>
        <apex:repeat value="{! newcases}" var="case" >
            <ul>
                <apex:outputLink value="/{! case.Id }" ><li>{! case.Id }</li></apex:outputLink>
                <li>{! case.CaseNumber }</li>
            </ul>

        </apex:repeat>
    </apex:pageBlock>

</apex:page>

when preview, says:

expecting a colon, found 'New' An unexpected error has occurred. Your development organization has been notified.

3
  • This is my view <apex:page controller="NewCaseListController" > <apex:pageBlock> <apex:repeat value="{! newcases}" var="case" > <ul> <apex:outputLink value="/{! case.Id }" ><li>{! case.Id }</li></apex:outputLink> <li>{! case.CaseNumber }</li> </ul> </apex:repeat> </apex:pageBlock> </apex:page> Jul 18, 2017 at 19:18
  • Hi, and welcome to SFSE! I took a moment to format your code for you. You can do this yourself in the future by using Ctrl-K or Cmd-K after highlighting your code.
    – sfdcfox
    Jul 18, 2017 at 19:26
  • Ctrl-K -> I did not know that. Kudos
    – glls
    Jul 18, 2017 at 19:38

2 Answers 2

3

Your SOQL is not properly formatted, the status "new" should be in between quotes

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

you can always check your soql in your developer console to validate it. you will notice that if you paste your original soql and try it out

SELECT Id, CaseNumber FROM Case WHERE Status = New

you will get an

'Unknown error parsing query'

0
-2
public with sharing class NewCaseListController {

    public List<Case> getNewCases() {

       string status = 'New';    
        List<Case> results = Database.query(
            'SELECT Id, CaseNumber FROM Case WHERE Status = :status '
        );
        return results;
    }
}
1
  • 3
    There's no need to use an Apex bind here. Please do make sure to include some description or explanation in your answers - a code dump is generally not very education to the asker or other community members.
    – David Reed
    Dec 6, 2018 at 12:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .