Skip to content

Naming of Classes and Triggers #5

@brianmfear

Description

@brianmfear

I'd just avoiding recommending Captain Obvious (CO) names, particularly Pages, Components, and Triggers.

You're in the triggers folder, looking at a file called AccountBeforeTrigger.trigger. This is clearly a trigger, so why did we call it a trigger? Just in case Salesforce gets confused? AccountBefore is a perfectly acceptable name.

Now, you're in the pages folder, looking at ProductSelection_VF.page. We know it's a Visualforce page, otherwise it wouldn't be in this folder. The exception to this rule is that Templates should be named as such: SiteChromeTemplate, or names that clearly define what the thing is: ProductSelectionWizard.

Finally, over in the components folder, why do we: AccountAddressLookupComponent.component? It's clearly a component, but we labelled it as such, again just in case it wasn't obvious. Even in normal Visualforce code, it gets its own name prefix, so there's no way we could confuse that component with a standard Visualforce element.

Next, I'd add suggestions about things you should name consistently:

MyPage has a controller named MyPageController, or, if a non-shared extension, MyPageExtension or MyPageExt (consistently).

Shared extensions (those that span multiple pages) should describe the feature, such as AddressLookupExtension or AddressLookupExt (consistently).

MyComponent has a controller named MyComponentController.

MyTrigger has a "helper class" named MyTriggerMethods or MyTriggerHandler (either sounds okay to me, but consistently).

Webservices classes should have a name that suggests this: GetFilesService or GetFilesWS (again, consistency).

REST Classes should similarly be named with consistency: GetFilesREST.

Utility classes should be named as such: AddressLookupUtil or AddressLookupUtility (either, but consistently).

Wrapper classes should end with the word Wrapper: AccountSearchWrapper.

Mock classes should end with the word Mock: HttpCustomServiceMock.

Exceptions should end with the word Exception: MyCustomException. (The platform actually enforces this, but it's good to know).

Webservices clients that call other services should ideally be called Client: MyCalloutClient.

All other classes that don't fit into any other category should be named as descriptively as possible, but without the word class or any prior word that suggests a particular use. For example: NameValuePair, VechicleIdentificationNumber, TshirtOrderData, etc.

Of course, I'm open to other suggestions, but a basic list of things you should do would help.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions