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.

  • 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> – Bravo Vlog Hector Bravo Jul 18 '17 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 '17 at 19:26
  • Ctrl-K -> I did not know that. Kudos – glls Jul 18 '17 at 19:38
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'

-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;
    }
}
  • 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 '18 at 12:17

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.