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

1 Answer

0 votes
by

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:-

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

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;

 } }

I. Programmatic Features – Salesforce Interview Questions

Related questions

0 votes
    I've got a problem with exposing a DTO class through SOAP WebService. My class looks like TKontrahent = ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I've got a problem with exposing a DTO class through SOAP WebService. My class looks like TKontrahent = ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 28, 2022 in Education by JackTerrance
0 votes
    I have recently discovered that salesforce.com is much more than an online CRM after coming across a Morrison's Case ... ' .Net route? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    What is the difference between public and global class in Apex Salesforce?...
asked Nov 11, 2020 in Technology by JackTerrance
0 votes
    What is an Apex transaction in Salesforce?...
asked Nov 11, 2020 in Technology by JackTerrance
0 votes
    I would really appreciate if someone can guide me to check if a particular field is included in update call inside ... . Many thanks. Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    Is there a way to determine if a trigger is being executed by an API call or through the Salesforce Web Interface ... updating to 26.0) Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    I would like to integrate SalesForce information into a .net MVC application. The samples on SalesForce website are ... .NET Thanks. Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I'm trying to execute a SOQL query using Salesforce REST API which will return 2,749 results. However, it seems ... the REST API. Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    Companies expose their services as a set of HTTP _____. Proxies Endpoints...
asked Sep 3, 2021 in Technology by JackTerrance
0 votes
    What are the different methods of batch Apex class?...
asked Nov 11, 2020 in Technology by JackTerrance
0 votes
    I'm trying to access my .xml file in the ClientBin with no success. code: WebClient xmlClient = ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    I have a web service class that will be in a managed package and distributed to multiple clients. The class ... accomplish this? Thanks Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    What is an external ID in Salesforce? Which all field data types can be used as external IDs?...
asked Nov 11, 2020 in Technology by JackTerrance
0 votes
    I want to expose multiple ports to the machine’s interface. How to achieve this using a docker container? Please help. Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
...