Which annotation is used to expose an Apex class as a REST web service?

Prepare for the Salesforce Integration Architect Test. Enhance your skills with detailed questions and insightful explanations. Equip yourself for success!

The annotation that is used to expose an Apex class as a REST web service is @RestResource. This annotation allows developers to define a class as a RESTful web service, enabling the class to handle HTTP requests and deliver responses in various formats such as JSON or XML. By utilizing @RestResource, the methods within the class can be mapped to specific HTTP methods such as GET, POST, PATCH, or DELETE, and can be accessed via a designated URL.

The choice to use @RestResource is essential for creating REST APIs in Salesforce, as it acts as the entry point for RESTful interactions with the Apex class. This facilitates the integration of Salesforce with other systems, allowing for seamless data access and manipulation.

The other options, while related to handling HTTP requests, do not serve the specific purpose of exposing an Apex class as a RESTful service. For instance, @HttpGet and @HttpPost are annotations that indicate methods that respond to GET and POST requests, respectively, but they need to be used within a class that is annotated with @RestResource to function correctly in a REST API context. The @ServiceEndpoint annotation is more relevant to SOAP web services rather than RESTful services.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy