Create Anonymous Salesforce Apex REST API with Platform

The REST API lets you integration with applications using standard HTTP methods. Using Apex REST you can expose the data that resides into your Salesforce instance and you can also get the data directly from the other system which hits the particular URL.

You can use below HTTP methods to expose the Salesforce data and vice versa


In this post, I’ll show you how to create an Apex Rest API which will expose Salesforce data which do not require authentication.

We will use Salesforce Site to create the API, using site will let us use APEX REST without authentication from any platform.

1 – Create a new Custom Object for this tutorial. Setup -> Create -> Objects -> New Custom Object -> Create New Object Student


2 – Now, we will create an Apex Class which will expose Student__c Object. Setup -> Develop -> Apex Classes -> New and copy the Apex code from Here and paste into Editor.

3 – Now, time to create a Salesforce Site. Setup -> Develop -> Sites. You will need a domain for the site and I will use studentAPI (You need to enter a valid domain) and Check Availabilty. Check  I have read and accepted the and then Register My Domain.


4 – Click New to create new Site


5 – After Saving You will be redirected to Site Detail Page which will look like below and Click on “Public Access Settings”


public access setting – Settings which can be access publically without login credentials. So, We will add our Apec Class in public access settings.

6 – Find “Enabled Apex Class Access”


7 – Edit, Find StudentController in Available Apex Classes and then Add into Enabled Apex Classes then Save it.


8 – Time to give permission to the Object (Student__C) that we have created earlier in the tutorial. Edit the Profile and find Student Object under Custom Object Permissions provide Read, Create, Edit and Delete Permission to Student Object. Save the Profile.



9 – Now time is to test the APEX REST API. We will use tool to test the same.

10 – Before we go for testing, we will need Endpoint URL to hit the APEX REST. For this, go to Setup -> Develop -> Sites -> Copy Site URL and paste into Notepad or any editor.


Note: – Site URL must be started with https no matter what is shown.

11 – We have copied the Site URL, however, this is not the complete. We will need to add some extra string that we used in our Apex class with services/apexrest/. Open apex class and copy the string after urlMapping. 


12 – Now, we will create the complete URL which will look like the combination of Site URL + /services/apexrest/ + Urlmapping String. After you will merge all three string URL will look like

12 – Time for some magic open Select Post For Method, Paste the complete URL. Headers – Add content Type as JSON. Click add body and use JSON for the body. Launch Request to create Student into Salesforce

“Name” : “Anonymous Student”


13 – You will get the response like below after successful creation of the record.


14 – Open Salesforce, go to student object and you will get the record there


15 – We have created Student record, now let’s fetch that record using the API. Create request like below and then launch request.


Response will be like below



Hope you enjoyed reading. If you have any question or issue please let me know in the comment section.

Resources: –



9 thoughts on “Create Anonymous Salesforce Apex REST API with Platform

  1. Dharmendra Bhuva July 17, 2019 / 5:46 am

    Hi Amit, Thank you for this article. I am trying to implement the same but with the standard object Case. I need to expose all the case records to site guest user. But I am not able to do it as guest user profile only show create and read permissions for case object. Can you help?


  2. Santiago G April 15, 2019 / 4:21 pm

    Thanks, it’s a very interesting post, do you know if any further Salesforce limits apply to this case? I mean, does any additional limits could apply using a Site instead of normal Rest Api connection? (such as max callouts per day, etc)


    • Amit Singh April 17, 2019 / 11:15 am

      Hi Santiago, Yes the limits will be same as for internal salesforce because we are making the api callins from other system to salesforce


      • Mallik December 28, 2018 / 7:09 am

        Thank you for the content. I have followed your step and I want to test my code now but I am not able to access the website Could you help me on that.

        and I request you to post many more posts as you explain them really well and it helps may more beginners like me.

        Thanks a ton.


      • Amit Singh December 30, 2018 / 4:31 am

        You can install DXC OR RestLest Chrome Extensions for the same


  3. Sunil June 18, 2018 / 3:29 am

    Thanks for the great Article 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s