Part-2 Create a record in salesforce using Salesforce REST API and Postman
Salesforce Rest API is a open source api from forcedotcom to enable easy access and edit to salesforce objects and metadata without using Salesforce UI itself.
Use Case: Consider you are a tester/developer and you need to perform “Create” operations (write) on salesforce objects like Account, Contact, Case, Opportunities, etc without actually logging into Salesforce UI. Then this post aims to provide step by step instructions of achieving the same.
Pre-requisites Setup:
- Already signed up for Salesforce Developer org.
- Postman is installed in system.
- Salesforce REST API is forked and added to personal workspace in Postman, as mentioned in the first part of my previous post:
Scenario:
In this example we will create a new record for “Case” Object.
Login to the salesforce developer account and Click on “Cases” tab under salesforce Classic view.
Click on “New” to create a new case. Following screen opens up
In the above screen we can see that there are combinations of fields, some are lookup fields like “Contact Name”, “Account Name” which needs to be searched and then selected. Few are dropdown list like “Type”, “Product” etc.And many are text fields with fixed field length while some are free text area fields like “Description”, “Internal Comments”, etc.
As a user I can select these fields and enter required details and then click on “Save” to insert/add this case data in Salesforce DB. This in turn will generate a CaseID which is autogenerated.
We can perform similar new case creation from “Salesforce Rest API” as well. But we should know the “API” names for these salesforce fields.
Navigate to “Setup” at top right corner of the screen, then search for Cases in the quick find as shown below. This will show “Cases” under “Build >> Customize >> Cases
Click on “Fields” under cases, this will bring up the list of fields which are available in Cases screen along with their “API” name.
We will be using these “API” names corresponding to each field Label and create a JSON request body like below:
{
"Type":"Electrical",
"Reason":"Installation",
"ContactMobile":"800-899-9023",
"ContactEmail":"Dellan.paul@email.com",
"Origin":"Phone",
"Product__c":"GC1060",
"Subject":"New product ordered",
"Description":"For creating new patient case record",
"Comments":"Note for helpdesk to assist customer with this case order."
}Procedure:
To create a record in Salesforce using the REST API, you will need to send a POST request to the Salesforce REST API endpoint for the specific object that you want to create a record for. The request body should contain the data for the fields of the new record in JSON format.
Get QA-init’s stories in your inbox
Join Medium for free to get updates from this writer.
In order to perform rest of the steps, please ensure pre-requiste setup#3 is completed:
- Salesforce REST API is forked and added to personal workspace in Postman, as mentioned in the first part of my previous post:
- First, we will need to authenticate to Salesforce and obtain an access token. You can use the OAuth 2.0 web server flow to authenticate and obtain an access token.
- Navigate to REST >> SObject >> SObject Create
Under “Param” tab, Path variable value is entered as “Case”.
3. In the body tab, enter the previously captured api details:
4. Click on ‘Send” to submit this post request.
5. As seen above we got error message in response since edit access is denied for these two fields. So we will remove these 2 fields and send request again:
“ContactMobile”:”800–899–9023",
“ContactEmail”:”Dellan.paul@email.com”,
6. This time response was success with “201 created” status, and a caseId was generated as shown below:
{
"id": "5004x00000S9UVaAAN",
"success": true,
"errors": []
}We can use this autogenerated id to query in Salesforce and confirm that this record was added to Cases record
7. Navigate to “Cases” tab in salesforce and we can see the newly created record.
Click on the caseId to open the record. All the field value matches with the values provided in “SObject Create” POST Request.
Conclusion:
In this way we can create/add new record in salesforce using “Salesforce REST API” without having to setup any additional configuration inside Salesforce Org.
That’s all for today. Please support my work by following my page and subscribing for future updates. Thanks for Reading.!!!









