1

So in salesforce while naming any custom object or any custom filed the spaces between the two words are replaced by an underscore and it add __c in the end. But why cannot they just remove space and add __c in the end why wasting memory for those extra underscores?

I mean if I name a custom field as Personal Score then in case of of writing the api name as Personal_Score__c why can't they just save it as PersonalScore__c / PersonalScore_c for more memory management. And what is the idea behind replacing the spaces into one single underscore between two words?

1
  • As a developer, I always change default API names of custom objects and fields to upper camel case, to be consistent with standard ones (such as OpportunityLineItem.ProductCode).
    – Trang Oul
    Jun 2, 2023 at 7:57

2 Answers 2

3

Spaces are used as delimiters in both Apex and SOQL so this would not compile:

myObject.Personal Score__c = 5;

whereas this will:

myObject.Personal_Score__c = 5;

and if you want to, you can shorten the API name to e.g.:

myObject.PersonalScore__c = 5;

Automatically replacing the space with an underscore is perhaps an arbitrary choice made by Salesforce designers a long time ago. For people who use all lowercase names it makes sense so e.g.:

myObject.personal_score__c = 5;

is probably a better result than:

myObject.personalscore__c = 5;

Memory impacts one way or the other are insignificant.

2
  • why __c why not _c? Jan 15, 2020 at 15:34
  • 1
    @Samswarup Decision made a long way in the past that if _ represents a space then __ represents a prefix or suffix separator. So xyz_A_c is not a custom field but xyz__A__c is a custom field A in the namespace xyz.
    – Keith C
    Jan 15, 2020 at 16:58
2

The amount of space salesforce.com would save is literally nothing, as the object names are stored in a database that presumably uses a CHAR field type for the name, for performance reasons. This means that "HelloWorld__c" and "Hello_World__c" both take up the same amount of space. The "__c" rule allows salesforce.com to introduce new objects with no chance of a naming conflict. The rule about replacing multiple spaces with a single underscore is again related to naming conflict prevention. If I can name an object Account__Share, that would conflict with the standard object (also assuming that the "__c" rule didn't exist). Also note... it's only the default. Many developers prefer to manually edit the object name so that no underscores are present, as this improves developer productivity by not having to type as many underscores.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .