How many times an external system has to interact and integrate data with your Salesforce environment? And how many times have you thought “How can I do it in the easiest way?”

Today I will show you a fast tool Salesforce provide you to enable external system to create record in salesforce with NO effort, and when I say no effort, I mean no code.

With Salesforce standard REST API an external system can create, update and upsert easily record by passing data in the body of the request.

For this first part I’m gonna show you how to authenticate and how to create and after edit a record you inserted.

Authentication

The authentication works more like when you use Workbetch: you insert your username and password and after that you perform action as the logged user.

To use the standard Rest API Salesforce provide (as for the custom API if you’ve implemented) you need first to get authenticated by the system. For this operation I used to create a connected app in salesforce that give a token to the external system that is used in the header of the request.

To do it first is good to create a custom profile and a custom user using that profile (i.e. Integration Profile and Integration User) to avoid the external system to create or edit record it has no visibility or edit right.

So first step is to create Connected App in Salesforce as showed in the print screen.

As Callback URL I insert the one used by postman to perform tests. (https://www.getpostman.com/oauth2/callback)

Now you’re ready to authenticate the external system in Salesforce.

In this first part I’ll show you how to create and update a record and how to perform query

Create a record

To perform call to Standard Rest Interface I’ll use Postman to emulate an external system. First we chose to use a POST call, set the url and path and then set the header.

The URL is standard for all object you want to create:

In this case I’ll create an Account, if you want to create another object even if custom you have to specify the object API Name.

From The previous authentication call we get a token so we have to add it in Authentication key and put behind Bearer as shown in the picture.

After that you should add Content-Type and Accept (optional) with value application/json.

Header is ready, lets start write the body: in it you have to insert Api name of the field. Everything works with API Name, so a Body could be something like this:

Some tips when you write the value of all the field in the body:

  • Date format: YYYY-MM-DD
  • DateTime format: YYYY-MM-DDThh:mm:ssZ
  • Picklist value: if you set a value different from label in picklist you have to use the value.
  • Lookup: indicate the Salesforce id. We will see in next ariticle ho to resolve lookup with external key

Just send the request and wait for the response:

If it success you’ll get the Salesforce Id otherwise in case of error you’ll get something like the response in the next snippet where it should be clear to understand the problem:

You can see the error is in the filed called Filed_Name__c and the problem is explained in the message value.

Update

As seen from the creation call in case of positive response Salesforce get back the Id of the created object. It can be used to call a similar Rest Api and update the record.

To do it you have to perform a PATCH call using the same url adding the SFDC Id as in this example:

So taking the Id from the previous creation call you have:

The body follows the same rule: you indicate the API Name of the filed you want to update.

If it success you’ll get a HTTP/1.1 204 No Content so it means the response doesn’t have body.

In case of error you’ll get the same structure as in creation step.

In this example i trued to put a number in a date filed and in the previous snippet you can see the response body.

Query

The last Rest API we see in this article is the one you can use to query record from external system as you use to execute in Deleveloper Console: to do it you should think first to the query and write it down.

Once you’ve written it you have to sostituire black space with + and for other symbols as apice you have to use URL accepted encoding %27.

So a simple query as:

becomes

To execute the query from external system you have to perform a GET call and you’ll get a response like this:

That’s it

Now you’re ready to create, update and retrive object from external system using standard Rest API. In the next part I show you how to create and update up to 200 record in one Rest call and ho to use external Id to resolve lookup.

 

Thank you,

Matteo.

(Visited 38 times, 1 visits today)