Salesforce REST API: Working with Salesforce SObjects using REST API
Looking for Salesforce Training & HandsOn Projects?
As most modern platform and programming languages supports
the usages for REST API based development methodologies. Almost every
programming language provides libraries & functions to ease working with
REST APIs.
Having access to REST APIs Endpoints for Salesforce Metadata
opens a whole new arena of possibilities for application developers who now can
design automated solutions targeting the Salesforce Platform in any programming
language they are comfortable in.
In this article, we explore how we can interact with Salesforce
SObjects using REST API Endpoints available for the Salesforce Platform. REST
API Endpoints for Salesforce offers CRUD operations but in this article, we
will discuss the Read Operations on Salesforce Standard & Custom SObjects.
Operation-1: Get the List of Salesforce SObjects
Preparing Request Object
Step-1: We can
get the list of available SObjects by following the REST API Endpoint template:
“<Salesforce Org
Header>/services/data/<API Version>/sobjects”
In this demo we will use the following Endpoint based on the
current Org & API configuration:
“https://na136.salesforce.com/services/data/v47.0/sobjects”
Step-2: Now click
on “Headers”
Step-3: Add “Authorization” Header and specify its
value as “Bearer
<Security Token Received>”. To know about getting Security Token, you can refer to my
earlier article Salesforce
REST API Authentication: The Login Request
Step-4: Once all configuration is done we can click the “Send” button to submit the API Request for Salesforce Endpoint
Analyzing Response Object
Step-5: If we analyze the Response Object we can see a list
of SObjects and all its properties, links to different metadata associated with
the SObject returned as shown below:
Lead Object
Operation-2: Get a Specific Standard Salesforce SObject
Preparing Request Object
Step-1: We can
get a specific SObject by following the REST API Endpoint template:
“<Salesforce Org
Header>/services/data/<API Version>/sobjects/<SObject API Name>”
In this demo we will use the following Endpoint based on the
current Org & API configuration:
“https://na136.salesforce.com/services/data/v47.0/sobjects/lead”
Step-2: Now click
on “Headers”
Step-3: Add “Authorization” Header and specify its
value as “Bearer
<Security Token Received>”. To know about getting Security Token, you can refer to my
earlier article Salesforce
REST API Authentication: The Login Request
Step-4: Once all configuration is done we can click the “Send” button to submit the API Request
for Salesforce Endpoint
Analyzing Response Object
If we analyze the Response Object we can see details on properties of Lead Object, links to different metadata associated with it
Step-7: Here we
focus only on the links to associated metadata with the SObject that is
returned as part of the response. These links provide a relative path to the
Endpoint for accessing a few of the most important implementations for the
Object.
For example: We can get quick access to the Data Views available for the respective SObject, using this Endpoint we can read the list views available for the SObjects.
Preparing Request Object
Step-8: We can get
the details on the Schema [Fields, Types, Relationships, and so on] for the SObject:
“<Salesforce Org
Header>/services/data/<API Version>/sobjects/<SObject API
Name>/describe”
In this demo we will use the following Endpoint based on the
current Org & API configuration:
Analyzing Response Object
Step-9: If we analyze the Response Object we can see more detailed information on Child Relationships for the respective (Lead Object in this case)
Step-10: If we analyze the Response Object we can see more detailed information on Fields & Properties for the respective (Lead Object in this case)
Step-11: If we analyze the Response Object we can see more detailed information on Fields Values, like in this case we can inspect the picklist values associated with a Field
Preparing Request Object
Step-13: We can get
the details about the specific record of the SObject by supplying Record Id as
a parameter to the REST API Endpoint:
“<Salesforce Org
Header>/services/data/<API Version>/sobjects/<SObject
Name>/<SObject Record Id>”
In this demo we will use the following Endpoint based on the
current Org & API configuration:
Analyzing Response Object
Step-14: If we
analyze the Response Object we can see more detailed information on the
specific record, with all field values saved as a transaction earlier. For
example: In the response object we can see details in the format:
“<Field API Name”:
“<Field Value>”
In this we can see values: FirstName, LastName, and Name and
so on as highlighted
Operation-5: Get a Specific Custom Salesforce SObject
Preparing Request Object
Step-1: We can
query details about the specific custom SObject in a similar way as Standard SObjects
by following the REST API Endpoint template:
“<Salesforce Org
Header>/services/data/<API Version>/sobjects/<Custom SObject API
Name>”
In this demo we will use the following Endpoint based on the
current Org & API configuration:
“https://na136.salesforce.com/services/data/v47.0/sobjects/Invoice_c”
Analyzing Response Object
Step-2: If we analyze
the Response Object we can see details on properties of custom Invoice_c
Object, links to different metadata associated with it
Step-3: We can
find more details as we tend to explore the response object more closely, like
here in Step-3 we can see the collection of recent items. Such information
could be very helpful to replicate Salesforce like functionalities in Custom
Third Party Applications.
Step-5: We can further explore the response object and can see details of the Invoice_c records with all its field values.
Hope you enjoyed this article. Please leave your comments to let me know how you do like the content and how you do find it helpful to learn the topic.
Comments
Post a Comment