top of page
Writer's pictureAmol Wagh

How to create public REST web service in salesforce

Updated: Aug 28, 2020

In this blog we are going to see how to create publicly accessible REST web service in salesforce.


Welcome to Cloudwaale blog. Best place to get step by step guide to learn new things in Salesforce. In this post we are going to see how to create public web service so let's start.

Step 1. Go to your name -> Developer Console ->File -> New -> Apex Class


Step 2. Write your own code, you can use following code for demo.


@RestResource(urlMapping='/firstwebservice')
 global class FirstWebService
  {
    @HttpGet
    global static String doGet() {
    String name = RestContext.request.params.get('id');
    return 'your Id is ==>'+name;
    }
   }

Step 3. Save above code with class name FirstWebService.


Now we are ready with our web service but it will not be accessible without Authentication, so to achieve our objective we need to make this web service as public,to make web service public continue with steps given below.


Step 4. To make web service public we need to create public site first, to create public site visit Setup -> Sites -> New -> Fill all required Details and Save


Step 5. Now we are ready with our public site, now we needs to give public access to our web service. click Public Access Setting -> scroll down and search for section Enabled Apex Class Access and click Edit you will get following page.


Step 6. Select your web service class and save.

Step 7. Now you can access your web service publicly by using -> Site Url/Services/Apexrest/Web service name.


Summery

That's it, we have done with web service which we can access publicly. To keep up with all the thing of Salesforce, customization, lightning, Apex, Visulaforce Page,REST and SOAP API and Tips and tricks to work with Salesforce head over to the Cloudwaale.


Thank you for visiting Cloudwaale, Please like and comment your view on this post.


Note: This Blog is Perspective of Author and not of Saleforce. This blog is only for study purpose.


3 comments

3 Comments


mryaremchyk
May 18, 2022

Thank you! For me it was extremely helpful and solved my task🤗

Like

raviavhad
Jun 11, 2019

Thanks for sharing this details, I was searching for same since very long but did not got proper explanation, but now this blog short out my problem.

Like

Aditya Zagade
May 19, 2019

Best blog for beginners

Like
bottom of page