Menu Close
    Start a Project Request quote Reading list Switch to dark mode

    @HttpGet Annotation In Salesforce

    In this blog we are going to learn about how to expose an Apex method  as a REST resource using @HttpGet annotation.

    rest annotation

    –> REST annotation enables you to expose an Apex class or an Apex method as a REST resource. In salesforce, there are six REST annotations, that is :

    1). @RestResource(urlMapping=’/your url’)

    2). @HttpGet

    3). @HttpPost

    4). @HttpPut

    5). @HttpPatch

    6). @HttpDelete

    –> Classes with REST annotation should be defined as global.

    –> Methods with REST annotation should be defined as global static.


    –> @HttpGet is used at method level. This method is called when a HTTP GET  request is sent. To expose your apex class as REST resource you should use @RestResource(urlMapping=’/your url’) annotation at class level as shown below.

    –> Here url mapping is relative to

    –> If your class is in namespace say ‘abc’, then API  url must be as follows:


    –> URL are case-sensitive.


    Let’s create an account by sending a parameter through API url.

    Step 1: Create an apex class  say ‘restExample’.

    Step:2: Now, to expose above rest class create a site as shown below. Goto>> SetUp>> Develop>> Sites

    # Register your domain:

    # Create New Site 

    # Copy the Default Web Address

    # Now goto Public Access Setting :

    # Provide Access to object which you want to expose in class.

    # Expose Apex class :

    That’s all for setting up of site.

    Step 3:  Now paste  Default Web Address(which you have copied from site setting) by appending:

    1). Without sending any parameter : ‘/services/apexrest/example’ . 

    2).  With parameter : ‘/services/apexrest/example?account_name=Webkul’

    Now, goto account page and verify your results.




    That’s all for @HttpGet Annotation In Salesforce, still if you have any further query feel free to add a ticket, we will be happy to help you

    . . .


    Add Your Comment

    Be the first to comment.

    Back to Top
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again

    Table of Content

    Hide Index