Naming conventions for Apex Class, Methods and Variables
Keeping the right name always makes the difference. Since Apex is case insensitive you can write it however you’d like. However, to increase readability, follow Java capitalization standards recommended by Salesforce.
- Classes start with a capital letter,
- Methods start with a lowercase verb, and
iii. Variable names should be meaningful.
Example 1:
public class Employee{ public Integer age; public String name; public void show(){ //body of method - } }
Example 2:
public class StudentDetails { public String name; public Integer age; public void studentDisplay(String sname, Integer sage){ name = sname; age = sage; system.debug('name of student: ' + name); system.debug('age of student: ' + age); } }
Example 3:
public class Foo{ public Boolean isClosed() { // some condition that returns true if something is true, else false } }
Note:
If the method returns a Boolean, make the method name an assertion statement. Here it is “isClosed”.