• #19412
    Salesforce | Manpreet Manpreet #232
    Forcetalks

    How can you expose an Apex class as a REST WebService in Salesforce?

    How can you expose an Apex class as a REST WebService in Salesforce?

     

    #19420
    Salesforce | Saurabh Saurabh #132
    Forcetalks

    Hi Manpreet

    you can expose your Apex class and methods so that external applications can access your code and your application through the REST architecture. This is done by defining your Apex class with the @RestResource annotation to expose it as a REST resource. You can then use global classes and a WebService callback method.

    Invoking a custom Apex REST Web service method always uses system context. Consequently, the current user’s credentials are not used, and any user who has access to these methods can use their full power, regardless of permissions, field-level security, or sharing rules.
    Developers who expose methods using the Apex REST annotations should therefore take care that they are not inadvertently exposing any sensitive data

    Look at the below piece of code for instance:-

    global class AccountPlan {
    webservice String area;
    webservice String region;
    //Define an object in apex that is exposed in apex web service
    global class Plan {
    webservice String name;
    webservice Integer planNumber;
    webservice Date planningPeriod;
    webservice Id planId;
    }
    webservice static Plan createAccountPlan(Plan vPlan) {
    //A plan maps to the Account object in salesforce.com.
    //So need to map the Plan class object to Account standard object
    Account acct = new Account();
    acct.Name = vPlan.name;
    acct.AccountNumber = String.valueOf(vPlan.planNumber);
    insert acct;
    vPlan.planId=acct.Id;
    return vPlan;
    } }

    Hope it may help

    #19421
    Salesforce | Suraj Suraj #163
    Forcetalks

    Hi Manpreet,

    Apex class and methods can be exposed for external applications access and your application through the REST architecture. Use @RestResource annotation with Apex class to expose it as a REST resource.

     

    • This reply was modified 1 year, 9 months ago by Salesforce | Suraj Suraj.
    #36415
    Salesforce | Parul Parul #2
    Forcetalks

    HI

    Apex REST Annotations
    Six new annotations have been added that enable you to expose an Apex class as a RESTful Web [email protected](urlMapping=’/yourUrl’)
    @HttpDelete
    @HttpGet
    @HttpPatch
    @HttpPost
    @HttpPut

     

    Thanks

Viewing 4 posts - 1 through 4 (of 4 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2019 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?