Salesforce REST API Playground

What is REST API ?

In my words, Getting data from Other System or Same System using HTTP request is known as REST API.

If you know, how website works, you know REST API. Before REST API, there was SOAP request which needed lots of configuration and very tightly coupled. If you make any modification , you had to modify client side also by generating stubs / proxy classes again. There were many more disadvantages which got address by REST API. However, it doesn’t mean we don’t need SOAP.

Back to REST API, It is very simple to setup and almost any programming language can make HTTP request so very easy to get data from other source. Return type of REST API can be XML, Simple HTTP, JSON or any media like image. However, JSON is very popular response type amongst all.

In Past, I have already written one article demonstrating REST API usage.

How to use Salesforce REST API using JQuery in Visualforce ?

REST API Playground : I have created Simple Visualforce page, which demonstrates how to use REST API of Salesforce. It is written in Visualforce with the help of JQuery. You can study this code and play with it in your organization, you just need to copy and paste it.

You also need to add URL “http://cdnjs.cloudflare.com” in Remote Site Settings, so that salesforce will allow Visualforce page to get JQuery library from CDN.

Video Demo :

REST API playground in Salesforce
REST API playground in Salesforce

Complete Visualforce page :

Related posts

  • The Zhong !

    You’re the MAN G2 !!! ^_^

  • murali

    good stuff at one place.

  • murali

    what might be the real business requirement to write this stuff on VF page…
    or for android app we might use REST API actions and q’s ?

    • JitendraZaa

      There may be many scenario. Like, If you want to get data from Other Salesforce Org as explained here – http://JitendraZaa.com/blog/salesforce/getting-record-from-one-salesforce-organization-to-other/ or creating Mobile app which depends on JSON data, JSON can be returned from REST API’s

      • murali

        thanks Jitendra.

        if i have given REST API instead of REST exposure from salesforce and barrier is oAuth without user name and password. how can we control data access like particular object and set of fields.

        • JitendraZaa

          In that case, you have custom rest service. So , to access anything you have to rely within logic of custom rest service. Also, if you have oauth token then no need of username and pass word.

          • murali

            ya …we can give custom rest class and Oauth with “access and manage your data”…if that person is trying to use REST API which is open and we can not able to see his operations and he can get data if he knows field api names and object of our org.

            in this case how can we control him

          • JitendraZaa

            In that case, you have to right logic inside your apex class which is exposed as rest. Right logging mechanism to log their actions…

          • murali

            but situation is different jitendra.
            suppose i have given custom rest class path and oAuth to java developer but he is using REST “API” (which is inbuilt for every salesforce org ) instead of my custom REST class with same oAuth which i have given earlier.

            in this case how we can control…

  • Ganesh Veerla

    Jitendra really this post is excellent.

  • Vinay Naidu

    very nice article.

  • ramesh

    this is not working in my visualforce page, how can i execute

    • JitendraZaa

      Hi Ramesh,
      Please try again. Formatting issue were before here.

      • reamesh

        Now it is working, Thank you Jitendra for this Post……..

  • kanna

    how can u reduce the code ?

  • kanna

    I mean how can you reduce the size of the code ?

  • Mupiri Rakesh

    Can anyone help me, how to send a csv file in a Rest Request, using Apex Class or Trigger

  • Selva Rathinam

    Really very nice…good stuff

  • Selva Rathinam

    I have one Question ..what is the maximum size of file (Or Record)we can send through REST Service..?suppose the record size is 10k ,how can i achieve this?