Notes
In Salesforce Apex, an sObject
(short for "Salesforce Object") represents a record in the Salesforce database. It is the base type for all Salesforce objects, and it corresponds to a row of data in a table. In other words, sObject
is the base class for all objects that can be persisted to the database, such as standard objects like Account
, Contact
, and custom objects defined by the user.
Key points about sObject
in Apex:
-
Dynamic Typing: sObject
provides dynamic typing, allowing you to work with different types of objects in a generic way. This is particularly useful when dealing with various record types in Salesforce.
-
Fields and Methods: sObject
includes methods and properties that allow you to access and manipulate the fields of the underlying record, such as getting and setting field values.
-
Common Operations: You can perform common database operations on sObjects
like insert, update, upsert, delete, and retrieve records from the database.
-
DML Operations: Data Manipulation Language (DML) operations, such as insert
, update
, and delete
, are used to persist changes made to sObjects
in the Salesforce database.
-
Database Querying: You can use SOQL (Salesforce Object Query Language) queries to retrieve records based on certain criteria.
Here's a simple example illustrating the use of an sObject
:
Create an Account sObject
Account acc = new Account();
acc.Name = 'Example Account';
acc.Industry = 'Technology';
insert acc;
Retrieve the Account record using SOQL and update it
Account retrievedAccount = [SELECT Id, Name, Industry FROM Account WHERE Id = 'ID Here' LIMIT 1];
retrievedAccount.Industry = 'Finance';
update retrievedAccount;
Delete an Account
Account retrievedAccount = [SELECT Id, Name, Industry FROM Account WHERE Id = 'ID HERE' LIMIT 1];
delete retrievedAccount;
Video
Video does not exists.