Home » What are Objects in Salesforce – Standard & Custom Objects

What are Objects in Salesforce – Standard & Custom Objects

  • by

Objects are the core of Salesforce. Objects are where Salesforce saves its data. In simple terms, objects are equivalent to tables in relational databases. Just like tables in relation databases, Salesforce objects also support various types of fields to save different types of data.

Standard Objects

Since Salesforce is an extensive application, it comes with a lot of pre defined objects i.e. objects provided by Salesforce. An example of these objects is Account, Contact, Opportunity, Case etc. We call these objects as Standard Objects.

Custom Objects

Since we know that Salesforce also allows us to build custom applications, to support this feature, Salesforce also allows users to create their own objects. User created objects are called as Custom Objects. The API name of custom objects always end with __c. We will discuss more about this when we learn about creating of custom objects.

Explore the objects in your org

To view the objects in an org, you can use the “Object Manager” in your org. If you still don’t have a Salesforce developer org, you can check my post “How to create a salesforce developer org” by clicking here. To open object manager, go to setup and type “object manager” in the quick find box.

setup

On opening the object manager you see a list of all the objects in the org.

Some of the main details shown on the object manager page are as follows

Object Label – This is an easy to read name of the object which appears at various places in Salesforce where a particular object is referenced. The Object name can contain spaces. Example or standard object labels are Opportunity, Account etc.

Object API Name – API name is what we need to use while doing development. For example if we need to write an SOQL query to get the Opportunity records, we will use the Opportunity API name. We will write such a query in Apex class as shown below.

List<Opportunity> oppList = [Select Id,Name,StageName From Opportunity];

API name cannot contain spaces. For custom objects, the API name is in a special format. We will discuss about this in the section below where we discuss creation of custom objects.

Object Type – This field simply shows whether an object is a standard object or a custom object.

Schema Builder – Schema builder is a very powerful tool which can give you a visual representation of all the objects in your org and shows relationships between various objects.You can also create custom objects using the schema builder.

How to create custom objects

To create the custom object click on the “Create” button in the object manager and the click on “Custom Object”

create custom object

In the Label field enter the text “Demo Object” and press the tab button on your keyboard. You will notice that Salesforce automatically populates the name “Demo_Object” in the Object Name. This is due to the fact that the Object Name is the API name of the custom object and cannot have spaces. You can change the API to name to something of your liking but it cannot have spaces. We will leave it as it is for now.

Salesforce also requires you to provide the plural label of the custom object. This name is also used in some places in Salesforce. Lets enter “Demo Objects” in the Plural Label textbox.

Now we need to provide the Record Name. Whenever we create a new custom object in Salesforce, it automatically creates a field with API name as “Name”. The Record Name textbox basically asks you to enter a label for this Name field. You can enter the “Demo Object Name” in the text box. Keep the value in Data Type drop down as “text”.

We do not need to make any more changes for now and click on the “Save” button at the bottom. Even though there are additional settings in the page but those are advanced functionalities which we will discuss in a later post. Just ensure that under the “Deployment Status” the value “deployed” is selected.

new custom object

After clicking the save button, you will see the following page

Notice the “__c” in the API name. Salesforce automatically appends the __c in the API name of custom objects. You do not need to do this and just specify an API name without space. In our case, we specified the API name as “Demo_Object” and Salesforce automatically added __c making the API name of the object as “Demo_Object__c”. The following code snipped shows how to query records of a custom object in an Apex class

List<Demo_Object__c> objList = [Select Id,Name From Demo_Object__c];

Now you are ready to start creating fields in the custom object. To create a new field, click on the “Fields & Relationships” menu in the left and then click the “New” button. By doing so, the new field wizard will start. Lets assume we want to create a String field with label “Demo Field”.

Since we want to create a String field, select “Text” in the Data Type section of the new field wizard and click next.

field type

In the field details page, enter the field label as “Demo Field” and press the tab button on the keyboard. Notice that in the Field Name field, the name “Demo_Field” name gets auto polulated. Like custom objects, custom fields also have a label and API name. Furthermore like custom objects, the API name of custom fields also cannot contain spaces. Finally like custom objects, Salesforce appends __c in the API name of the custom fields. Hence the api name of the new field will be “Demo_Field__c”. Provide a desired length in this case as we are creating a String field and click next.

custom field details

The next screen is used to set field level security. This is a very important concept in salesforce and pertains to who can see the data in this field. We will discuss more about this in upcoming posts. For now make the field visible to all the profiles and click next.

field visibility

Click save in the final page also without making any changes.

save new field

Congratulations, you have created your first custom field. The following code snipped shows how to query records of a custom object in an Apex class.

List<Demo_Object__c> objList = [Select Id,Name,Demo_Field__c From Demo_Object__c];

You can also check the saleforce trailhead giving details of objects by clicking here.

With this I conclude this post regarding objects in Salesforce.