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
sainath .chalamcherlasainath .chalamcherla 

Hi everyone, i am new to salesforce platform i am practicing salesforce trailhead challnges i am getting error in TOPIC: CREATE AND USE CUSTOM CONTROLLERS .ERROR NAME:EXPECTING RIGHT PARENTHESIS FOUND 'NEW'AT LINE3 COLUMN'37' my CODE:

Best Answer chosen by sainath .chalamcherla
SandhyaSandhya (Salesforce Developers) 
Hi Sainath,

If you are trying for the example code given in the module.Then Please refer below full code.

Visualforce page
 
<apex:page controller="ContactsListController">
    <apex:form >
        <apex:pageBlock title="Contacts List" id="contacts_list">
            
            <!-- Contacts List goes here -->
            
            <!-- Contacts List -->
<apex:pageBlockTable value="{! contacts }" var="ct">

<apex:column value="{! ct.FirstName }">
    <apex:facet name="header">
        <apex:commandLink action="{! sortByFirstName }" 
            reRender="contacts_list">First Name
        </apex:commandLink>
    </apex:facet>
</apex:column>

<apex:column value="{! ct.LastName }">
    <apex:facet name="header">
        <apex:commandLink action="{! sortByLastName }" 
            reRender="contacts_list">Last Name
        </apex:commandLink>
    </apex:facet>
</apex:column>

    <apex:column value="{! ct.Title }"/>
    <apex:column value="{! ct.Email }"/>
    
</apex:pageBlockTable>

        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller
 
public with sharing class ContactsListController {
private String sortOrder = 'LastName';
    
public List<Contact> getContacts() {
    
    List<Contact> results = Database.query(
        'SELECT Id, FirstName, LastName, Title, Email ' +
        'FROM Contact ' +
        'ORDER BY ' + sortOrder + ' ASC ' +
        'LIMIT 10'
    );
    return results;
}

public void sortByLastName() {
    this.sortOrder = 'LastName';
}
    
public void sortByFirstName() {
    this.sortOrder = 'FirstName';
}
}

And if you are trying the challenge please refer below code.
 
<apex:page controller="NewCaseListController">
    <apex:pageBlock title="new Case List" id="cases_list">
        <li>
            <apex:repeat var="case" value="{!newCases}" rendered="true" id="rCases">
                <p><apex:outputLink value="/{!case.ID}">{!case.CaseNumber}</apex:outputLink></p>
            </apex:repeat>
		</li>
    </apex:pageBlock>
</apex:page>
 
public class NewCaseListController {
    public List<Case> getNewCases() {
    
        List<Case> results = [SELECT CaseNumber FROM Case WHERE status='New'];
            return results;
    }
}

Hope this helps you!


Please mark it as Best Answer if my reply was helpful. It will make it available for other as the proper solution.
 
Thanks and Regards
Sandhya