Activity Forums Salesforce® Discussions What set of naming convention to use when developing on the Force.com platform?

  • Anjali

    Member
    September 6, 2018 at 5:28 am

    Hi Madhulika,
    Follow the CamelCase Java conventions, except for VF pages and components start with a lower case letter.

    Triggers:  <ObjectName>Trigger - The trigger itself. One per object.
    <ObjectName>TriggerHandler - Class that handles all functionality of the trigger
    <ObjectName>TriggerTest

    Controllers:    <ClassName>Controller
    <ClassName>ControllerExt
    <ClassName>ControllerTest
    <ClassName>ControllerExtTest

    Classes:  <ClassName>
    <ClassName>Test (These might be Util classes or Service classes or something else).

    Visualforce pages and components:  <ControllerClassName>[optionalDescription] (without the suffix Controller). There might be multiple views so could also have an extra description suffix.

    Object Names and custom Fields:  Upper_Case_With_Underscores

    Variables/properties/methods in Apex:  camelCaseLikeJava - more easily differentiated from fields

    Test methods in test classes:  test<methodOrFunctionalityUnderTest><ShortTestCaseDesc> - For example, testSaveOpportunityRequiredFieldsMissing, testSaveOpportunityRequiredFieldsPresent, etc.

    Working on something that would be used as an app or  a project, then do the following:

    Prefix all custom objects, apex classes, Visualforce pages and components with an abbreviation so that they are easier to identify (e.g., easier for changesets). For example the WidgetFactory app would have the prefix wf on those. Additionally, when adding custom fields to a standard object they would also be prefixed to identify them as part of the app/package.

  • Anurag

    Member
    September 10, 2018 at 8:02 am

    Hi Madhulika,

    It is not legal to define a class and interface with the same name in the same class. It is also not legal for an inner class to have the same name as its outer class. However, methods and variables have their own namespaces within the class so these three types of names do not clash with each other. In particular it is legal for a variable, method, and a class within a class to have the same name. Following Java standards for naming, that is, classes start with a capital letter, methods start with a lowercase verb, and variable names should be meaningful.

  • Parul

    Member
    September 18, 2018 at 4:19 am

    Hi,

    The main reason for the Naming convention using Upper_Case_With_Underscores is that when you type in the name field or object with spaces it automatically adds the underscores. Although Apex is case insensitive, always refer to the Objects and Custom Fields in the code as Upper_Case_With_Underscores as well for consistency all around and consistency with what is generated by the SOQL schema browser and other tools. Object and Field Labels (which are generally ignored by code but visible to users) should keep spaces, not underscores. Instead of having to think about how something should be formatted or what something should be named they can just follow the standards and focus their thinking on solving the larger problems.

    Scheduled and Batch Apex Classes
    <descriptive>Scheduler
    <descriptive>Batch
    Examples: CartCleanupScheduler, CartCleanupBatch

    Triggers and Trigger Handlers
    <sObject>Trigger
    <sObject>TriggerHandler
    Examples:  AccountTrigger, AccountTriggerHandler

    Utility Classes
    <descriptive>Utils
    Examples: PageUtils, LogUtils, StringUtils

    Wrapper Classes
    <sObject>Wrapper
    Examples:  AccountWrapper, OpportunityWrapper, CaseWrapper

    Value Objects
    <descriptive> – That is all.
    Examples: MapLocationRequest, MapLocationResponse

     

    Thanks

     

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos