Apex Naming conventions

As a developer, I stumble upon in many occasions about naming conventions in Apex.

In official documentation salesforce recommends to use the Java naming conventions.

This post is fully dedicated to for naming conventions in apex program only. I will give naming conventions for standard salesforce functionalities like workflow, Sharing rules, etc... in upcoming post.

ok let's start,

Trigger

<Objectname>Trigger

For example: For account the trigger name should be AccountTrigger.

The First letter of the trigger should always be capital.

I always have only one trigger per object. It will help you in many ways like tracking the bug and giving a clear idea of order of execution. And I suggest you follow the same thing.

Trigger utility class

<Objectname>TriggerUtility

The First letter of the trigger should always be capital.

I won't write trigger logic inside trigger. Try to put it in utility class. My trigger class will look like a skeleton just check for events and call the method in utility class.

Controller

Apex controller

<Object><Functionality>Controller

The First letter of the controller should always be capital.

For example: If it's a controller which is related to searching for account records then it should be "AccountSearchController".

If it's related to Visualforce page which has nothing to do with a specific object.

Then just <Functionality>Controller like SearchController

Apex class instance variable

Apex class instance variable should follow camel case naming conventions.

Camel case is nothing but starting with a lower case letter followed by upper case letter for every new word.

Example: helloWorld

Single variable

While naming a single variable, you should have something which has a meaning in it.

Example: forceWizardAccount

List

<instanceName>List

Example: highValueOpportunityList

Set

<instanceName>Set

Example: highValueOpportunitySet

Map

<instanceName>Map

Example: highValueOpportunityMap

Boolean

is<InstanceName>

Example: isHighValueOpportunity

Apex class instance methods

Apex class instance methods should follow camel case naming conventions.

Example: public void updateAccount(){}

Apex extensions

<Object><Functionality>Extension

Example : AccountCountExtension

Batch apex

<Object><Functionality>Batch

The First letter of the batch should always be capital. 

For example: If it's a controller which is related to updating a close date for account records then it should be "AccountCloseDateBatch".

If it's related to a specific functionality which has nothing to do with a specific object.

Then just <Functionality>Batch like SendOfferEmailBatch

Apex scheduler 

<Object><Functionality>Scheduler

The First letter of the scheduler should always be capital. 

For example: If it's a controller which is related to updating a close date for account records then it should be "AccountCloseDateScheduler".

If it's related to a specific functionality which has nothing to do with a specific object.

Then just <Functionality>Scheduler like SendOfferEmailScheduler

Test class

<ClassName>Test

The First letter of a test class should always be capital. 

For example: 

Controller name: AccountSearchController

TestClass name: AccountSearchControllerTest

It follows for all kind of apex class controller, batch, scheduler etc...

Visualforce page

For a specific functionality 

<Functionality>

The First letter of a visualforce page should always be capital. 

For example: AccountSearch

If you are overriding a button in an object then,

Override_<Object>_<new/edit>

For example: OverrideAccountEdit

Apex components

<Functionality>Component

Example: ProductInformationComponent

Let me know if have missed out some things in comments.

Happy coding laugh !!!

Rating: 
Average: 5 (1 vote)