You need to sign in to do that
Don't have an account?
DMalone
Trailhead: Creating & Using Custom Controllers error
I'm on the second to last unit of the Visualforce Basics module, called Creating & Using Custom Controllers.
I THINK I have followed everything correctly (being new to coding) but I'm getting an error when in the section Add A New Action Method:
line 7: expecting a semi-colon, found "("
The custom controller I am trying to use is as follows and the line in bold is line 7:
public class ContactsListController {
private String sortOrder = 'LastName';
public List<Contact> getContacts() {
public void sortByLastName() {
this.sortOrder = 'LastName';
}
public void sortByFirstName() {
this.sortOrder = 'FirstName';
}
List<Contact> results = Database.query(
'SELECT Id, FirstName, LastName, Title, Email ' +
'FROM Contact ' +
'ORDER BY ' + sortOrder + ' ASC ' +
'LIMIT 10'
);
return results;
}
}
Any ideas on where I have gone wrong?
Thanks
Dan
I THINK I have followed everything correctly (being new to coding) but I'm getting an error when in the section Add A New Action Method:
line 7: expecting a semi-colon, found "("
The custom controller I am trying to use is as follows and the line in bold is line 7:
public class ContactsListController {
private String sortOrder = 'LastName';
public List<Contact> getContacts() {
public void sortByLastName() {
this.sortOrder = 'LastName';
}
public void sortByFirstName() {
this.sortOrder = 'FirstName';
}
List<Contact> results = Database.query(
'SELECT Id, FirstName, LastName, Title, Email ' +
'FROM Contact ' +
'ORDER BY ' + sortOrder + ' ASC ' +
'LIMIT 10'
);
return results;
}
}
Any ideas on where I have gone wrong?
Thanks
Dan
Try this:
All Answers
Apologies.
How's this? Long term admin, new to dev stuff :)
Try this:
Now no more errors! :)
I misread the instructions I think and got things in the wrong order. Thank you very much for you help Andy, much appreciated.
Now I can enjoy Christmas in peace ;)
Dan
Will send feedback to Trailhead on this one. The instructions for WHERE to add the two action methods (sort by first name, sort by last name) were confusing. After the Get Contacts method is where it goes, but not right after that line. Those methods aren't added until after the return results section and right before the closing bracket.