Creating Webservices using sites in Salesforce and access as REST API

By | June 4, 2018

The Salesforce REST API lets you integrate Salesforce applications using standard HTTP methods. This can then be used to integrate Salesforce with Sage ERP. 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 webservice(URL).Since we are exposing the data to public access with this approach so be cautious with security setups in Salesforce org. 

We will use Salesforce Site as our webservice 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-

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.
“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 – a globally recognized and one of the oldest Sage Development Partner and a Salesforce Product development partner offers a wide variety of integration products and services to the end users as well as to the Partners and Sage PSG across the globe. We offer Consultation, Configuration, Training and support services in out-of-the-box functionality as well as customizations to incorporate custom business rules and functionalities that require apex code incorporation into the Salesforce platform.

Greytrix has some unique solutions for Cloud CRM such as Salesforce Sage integration for Sage X3Sage 100 and Sage 300 (Sage Accpac). We also offer best-in-class Cloud CRM Salesforce customization and development services along with services such as Salesforce Data MigrationIntegrated App developmentCustom App development and Technical Support to business partners and end users.
Salesforce Cloud CRM integration offered by Greytrix works with Lightning web components and supports standard opportunity workflow. Greytrix GUMU™ integration for Sage ERP – Salesforce is a 5-star rated app listed on Salesforce AppExchange.

The GUMU™ Cloud framework by Greytrix forms the backbone of cloud integrations that are managed in real-time for processing and execution of application programs at the click of a button.

For more information on our Salesforce products and services, contact us at We will be glad to assist you.

Related Posts