Follow the CamelCase Java conventions, except for VF pages and components start with a lower case letter.
- <ObjectName>Trigger - The trigger itself. One per object.
- <ObjectName>TriggerHandler - Class that handles all functionality of the trigger
(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
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 in some cases just a project? If yes, 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.
The main reason for the Object and Fields Names 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.
Does Schema.GetGlobalDescribe() Account for Prefixes?
SObjectType.Obj__c.Name to resolve the namespace, for example:
String fullyQualifiedName = SObjectType.Obj__c.Name;
String label = Schema.GetGlobalDescribe().get(fullyQualifiedName).getDescribe().getLabel();
Edit: dynamic method
Replace line 1:
String fqName = Type.forName(isPkg ? 'ns' : '', 'Obj__c').getName() where
ns is set only in the packaging org, eg via Protected Custom Setting
The method returns a
Map<String, Schema.SObjectType>. The
Stringkey is the lower-case
getmethods on this map are case-insensitive). It contains every object in your org.
You can also debug them one by one:
You should be able to answer this question yourself by simply reading the
Schemaclass documentation. Relevant bit: