Visualforce Controller Class Convention

A quick post to outline an informal convention for the definition of a Visualforce controller class, key maintainability characteristics being predictable structure, readability and prominent revision history. All developers have a subjective preference in this regard, however consistency is key, particularly in the Salesforce context where multiple developers/consultancies contribute to a codebase over its lifetime. A simple, logical approach always makes sense to maximise adoption.

Name:  MyPageController.cls
Copyright © 2014  Force365
Controller class for the VF page -
Ver. Author        Date        Detail
1.0  Mark Cane&    2014-05-20  Class creation.
1.1  Mark Cane&    2014-05-21  Initial coding for page initialisation.
public with sharing class MyPageController {
	//& public-scoped properties.	
	public List<MyWrapperClass> wrapperClassInstances { get; set; }
	//& End public-scoped properties.
	//& private-scoped variables.
	private Boolean isInitialised=false;
	//& End private-scoped variables.
	//& page initialisation code.
	public MyPageController(){
	private void initialise(){ isInitialised=true; }
	//& End page initialisation code.
	//& page actions.
	public PageReference saveAction(){
		return null;
	//& End page actions.
	//& data access helpers (class methods accessed from binding expressions).
	//& End data access helpers.
	//& controller code Helpers (class methods providing helper functions to data access helpers or actions).
	//& End controller code helpers.
	//& inner classes (wrapper classes typically, extending SObjects for convenience in the UI).
	public class MyWrapperClass {
		public MyWrapperClass(){}
	//& End inner classes.
%d bloggers like this: