Salesforce Naming Conventions

 Salesforce has specific naming conventions for different elements to ensure consistency, readability, and maintainability in your code and configuration. Following these conventions also makes it easier for developers and administrators to collaborate. Here are some key naming conventions in Salesforce:

1. Classes, Interfaces, and Triggers

  • Naming Format: Use CamelCase (uppercase first letter for each word).
  • Class Names: Should be descriptive and convey the purpose of the class.
  • Example:
    • AccountHandler
    • LeadService
    • OpportunityTriggerHelper

2. Methods and Variables

  • Naming Format: Use camelCase (lowercase first word, uppercase for subsequent words).
  • Method Names: Should clearly state the action or purpose.
  • Example:
    • calculateTotalPrice
    • updateLeadStatus
  • Variable Names: Should describe the data they store.
  • Example:
    • totalAmount
    • isActive

3. Constants

  • Naming Format: Use ALL_CAPS_WITH_UNDERSCORES.
  • Example:
    • MAX_RETRIES
    • DEFAULT_TIMEOUT

4. Custom Objects

  • Naming Format: Use PascalCase (uppercase first letter of each word, no spaces or underscores).
  • Object Names: Should be singular (best practice) and descriptive of the object.
  • API Name: Automatically ends with __c to signify it is custom.
  • Example:
    • Invoice__c
    • PaymentSchedule__c

5. Custom Fields

  • Naming Format: Use PascalCase (for API name) and descriptive names.
  • API Name: Ends with __c to denote it is custom.
  • Example:
    • TotalAmount__c
    • DueDate__c
  • Field Labels: Can have spaces and should be more readable for users.
    • Example: Total Amount, Due Date

6. Custom Relationships

  • Lookup Relationships:
    • Field API Name: Ends with __r for relationships.
    • Example: Account__r
  • Master-Detail Relationships:
    • Parent-Child Field API Names: Should be descriptive of the relationship.
    • Example: Account__r, Orders__r

7. Triggers

  • Naming Format: Use ObjectNameAction format to indicate the object and the action/event.
  • Example:
    • AccountBeforeInsert
    • LeadAfterUpdate
    • OpportunityBeforeDelete

8. Test Classes

  • Naming Format: Use ClassNameTest format.
  • Example:
    • AccountHandlerTest
    • OpportunityServiceTest

9. Apex Properties

  • Naming Format: Use camelCase.
  • Example:
    • isValid
    • totalRecords

10. Visualforce Pages and Components

  • Naming Format: Use PascalCase for the names of pages and components.
  • Example:
    • OrderSummaryPage
    • LeadInfoComponent

11. Lightning Components (Aura/LWC)

  • Component Names: Use camelCase for component names.
  • Bundle Names: Should be descriptive.
  • Example:
    • accountInfo
    • orderSummary

12. SOQL Queries

  • Aliases: Use lowercase and descriptive aliases in SOQL.
  • Example:
    • SELECT Id, Name FROM Account a WHERE a.Industry = 'Tech'

13. Permissions, Profiles, and Roles

  • Naming Format: Use PascalCase and ensure the name reflects the role or permission.
  • Example:
    • SalesManager
    • FinanceAdmin

14. Reports and Dashboards

  • Naming Format: Use PascalCase and ensure the name reflects the content of the report or dashboard.
  • Example:
    • SalesPerformanceReport
    • MonthlyRevenueDashboard

Best Practices

  • Avoid Abbreviations: Unless widely understood, avoid abbreviating words in your names.
  • Be Descriptive: Make names descriptive enough to convey the purpose without being overly verbose.
  • Consistency: Follow the same naming style across all elements for consistency.

By adhering to these conventions, you’ll make your Salesforce setup more readable, maintainable, and easier for other team members to understand and work with.

Comments

Popular posts from this blog

API Names in Salesforce

18 - LWC - BEST PRACTICES - For accessing HTML elements and their values in JavaScript

6 - Object Relationships (Lookup and Master-Detail and Junction Objects)