Creating an endpoint in Salesforce and using REST API to externally access it

By | June 4, 2018

The Salesforce Force.com REST API lets you integrate Salesforce applications using standard HTTP methods. This can then be used to integrate Salesforce with other systems. With help of Apex REST, we can expose the data from Salesforce orgs and we can also fetch data from other systems which hits the particular endpoint (URL).

We will use Salesforce Site as our endpoint where most of the action will happen. For our demo purpose, we will create a Custom object named “Demo”. Once the object is created using the below code.

Creating Demo Object

Creating Demo Object

Apex Class code for Demo Controller

Apex Class code for Demo Controller

Now, create a site in Salesforce, if you are new and if you need not know how to create a site in Salesforce then refer this link. Once your site is created in its “Public Access Settings” then add the above created Class into “Enabled Apex Classes” and save it. Then at profile level just enable the Read, Create, Edit and Delete access to the “Demo” object. Now, that the configuration and coding are completed, its time to test the REST API.

From your site section select the URL of your newly created site and append it with “services/apexrest/” and URLMapping mentioned in the code at the end. Your URL must look something like this-
https://<>/services/apexrest/Demo/

Now, let’s add a record from an external system to Salesforce using REST API, for this, we will be using Google’s ARC (Advanced REST Client). In the Header section Add content type as JSON and then click add body and use the below JSON as body and use “POST” Method to post data from ARC to Salesforce.
JSON-
{
“Name”: “REST Demo”
}

Once you execute the request then you should receive status code 200 denoting success and in response, you should receive the record id of the record just created.

Response that record is created

Response that record is created

To verify you can simply use the “GET” method to fetch the data and see for yourself.

So, in this way you can simply test the REST API from Salesforce.

About Us
Greytrix is one stop solution provider for Sage ERP and Sage CRM needs. We provide complete end-to-end assistance for your technical consultations, product customization’s, data migration, system integrations, third-party add-on development and implementation expertise.

Greytrix has some unique solutions for Cloud CRM such as Salesforce integration with Sage X3, Sage 100 and Sage 300. We also offer best-in-class Cloud CRM Salesforce customization and development services to business partners and end users. Greytrix has some unique solutions for On-Premise CRM such as Sage CRM integration with Sage X3, Sage 100, Sage 300, Sage 500 and Sage 50. We also offer best-in-class On-Premise Sage CRM customization and development services to business partners and end users.

For more information, please contact us at [email protected]. We will be glad to assist you.

Related Posts