Menu Close
    Start a Project Request quote Reading list Switch to dark mode
    hyperlocal-marketplace-guide

    @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

    –> @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 https://instance.salesforce.com/services/apexrest/.

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

    •  https://instance.salesforce.com/services/apexrest/abc/you_url

    –> URL are case-sensitive.

    Example

    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.

    Output

     

    Support

    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 https://webkul.uvdesk.com/en/customer/create-ticket/.

    . . .

    Comment

    Add Your Comment

    Be the first to comment.

    Back to Top
    css.php
    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
    Close

    Table of Content

    Hide Index