Salesforce organizes all data into a hierarchy of database objects called SObjects. SObject is a term unique to Salesforce that refers to any object in the Salesforce database that can be represented by a record. Understanding SObjects is key to effectively working with Salesforce.
What is an SObject
An SObject is a database table that holds information for a specific Salesforce object. For example, the Contact SObject holds all the contact records, the Account SObject holds all the account records, and so on.
Some key things to know about SObjects:
- SObjects allow access to records in the database through the Salesforce API
- The fields, relationships and behaviors of an SObject are defined in the Salesforce metadata
- There are standard SObjects provided by Salesforce, like Account and Contact, as well as custom SObjects defined by administrators and developers
- SObjects simplify the way data is accessed and stored in Salesforce
In code, SObjects can be handled generically through interfaces like sObject and SObject. The sObject interface allows manipulating records without knowing the specific SObject type.
Standard vs Custom SObjects
There are two types of SObjects in Salesforce:
Standard SObjects – These refer to built-in database objects like Account, Contact, Lead, and Opportunity. Standard objects come out-of-the-box with any Salesforce org.
Custom SObjects – Custom SObjects are database tables that allow you to store custom data in Salesforce, beyond what the standard objects provide. For example, you can have a Project SObject to track project details. Custom objects need to be defined by administrators or developers.
The behaviors and relationships allowed between standard and custom SObjects differ based on the Salesforce edition. But both serve as containers for storing related data.
SObject Relationships
SObjects connect to other SObjects through relationships, which allow related data across SObjects to be queried, displayed and reported on.
Some common SObject relationships in Salesforce include:
- Lookup relationship – Links two SObjects together via an id, like Contact and Account
- Master-detail relationship – Links two SObjects, allows delete cascading and rollup summaries
- Many-to-many relationship – Links two SObjects via a third junction object
- Self relationship – Links an SObject to other records of the same SObject
Understanding SObject relationships is key for accessing and reporting on related data that lives in multiple database tables.
SObject Fields
SObjects consist of fields that define the data stored in each object record. There are two types of fields in Salesforce:
Standard Fields – Predefined fields that come out of the box with each standard and custom SObject, like Name, CreatedDate, LastModifiedDate etc.
Custom Fields – Additional fields defined by admins/developers to capture custom data, like Region, Department, Discount Percent etc.
Fields have attributes like data types, length restrictions, and default values that determine what and how data can be stored. Standard and custom fields enable admins to customize what data gets tracked at the object level.
Working with SObjects
Here are some common ways to work with SObjects in Salesforce:
SOQL – Query SObjects using Salesforce Object Query Language. For example:Copy code
SELECT Name, BillingCity FROM Account
SOSL – Search SObjects using Salesforce Object Search Language. For example:Copy code
FIND {test} IN ALL FIELDS RETURNING Contact(Name, Email), Account(Name)
API Access – Manage SObject CRUD (create, read, update, delete) operations using Salesforce APIs like REST, BULK, and SOAP.
Apex – Access SObjects programmatically on the Salesforce platform using Apex and add custom logic and automation.
MetaData API – Update SObject metadata like fields and relationships programmatically.
Understanding how to manipulate SObjects enables almost all programmatic access and customization of Salesforce data.
Summary
In summary, SObjects are custom or standard database tables that hold records for Salesforce data. They consist of fields, relationships and behaviors that determine how data is stored and connected. SObjects can be accessed through various APIs and provide the basic building blocks for organizing business data across Salesforce. By understanding SObjects, admins, developers and power users can effectively structure, query, access and manage data as per business needs on the Salesforce platform.