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:
AccountHandlerLeadServiceOpportunityTriggerHelper
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:
calculateTotalPriceupdateLeadStatus
- Variable Names: Should describe the data they store.
- Example:
totalAmountisActive
3. Constants
- Naming Format: Use ALL_CAPS_WITH_UNDERSCORES.
- Example:
MAX_RETRIESDEFAULT_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
__cto signify it is custom. - Example:
Invoice__cPaymentSchedule__c
5. Custom Fields
- Naming Format: Use PascalCase (for API name) and descriptive names.
- API Name: Ends with
__cto denote it is custom. - Example:
TotalAmount__cDueDate__c
- Field Labels: Can have spaces and should be more readable for users.
- Example:
Total Amount,Due Date
- Example:
6. Custom Relationships
- Lookup Relationships:
- Field API Name: Ends with
__rfor relationships. - Example:
Account__r
- Field API Name: Ends with
- 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:
AccountBeforeInsertLeadAfterUpdateOpportunityBeforeDelete
8. Test Classes
- Naming Format: Use ClassNameTest format.
- Example:
AccountHandlerTestOpportunityServiceTest
9. Apex Properties
- Naming Format: Use camelCase.
- Example:
isValidtotalRecords
10. Visualforce Pages and Components
- Naming Format: Use PascalCase for the names of pages and components.
- Example:
OrderSummaryPageLeadInfoComponent
11. Lightning Components (Aura/LWC)
- Component Names: Use camelCase for component names.
- Bundle Names: Should be descriptive.
- Example:
accountInfoorderSummary
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:
SalesManagerFinanceAdmin
14. Reports and Dashboards
- Naming Format: Use PascalCase and ensure the name reflects the content of the report or dashboard.
- Example:
SalesPerformanceReportMonthlyRevenueDashboard
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
Post a Comment