Integration: 11% Flashcards
How do you expose an Apex class as a REST API?
The class must be global and annotated with the @RestResource annotation. The parameter of the @RestResrouce annotation, urlMapping is used to uniquely idnetify your resource and is relate to the base URL https://instance.salesforce.com/services/apexrest
True or False: All Apex REST methods must be global static?
True
What does @HttpGet mean?
The @HttpGet annotation exposes the method as a REST API that is called when an HTTP GET request is sent from the client
What does @HttpPost mean?
The @HttpPost annotation exposes the method as a REST API and is called when an HTTP POST request is sent form the client.
How do you expose an Apex class as a SOAP Webservice?
By creating a global Class, and then create a web service method within the class. These methods will inherit the global access of their parent class.
Example: global with sharing class MySOAPWebService { webservice static Account getRecord(String id) { // Add your code } }
True or False: Webservice methods cannot be static
False: webservice methods must be static
True or False: Webservice methods can be overloaded
False: webservice methods cannot be overloaded
Can the webservice keyword be used in any code contained in a trigger?
False, the webservice keyword cannot be used in any code contained in a trigger
When would you use the @ReadOnly annotation in a Web Service?
To allow unrestricted queries when no DML operations are necessary
What does Apex support for the WSDL?
Apex supports:
- A limited set of WSDL schema types
- The element and sequence WSDL schema constructs
- Blob, decimal, and enum for call ins but not for call outs
What does Apex not support with WSDL?
Apex does not support
- Encoded services
- WSDL files with multiple portTypes, multiple services or multiple bindings
- WSDLs that exceed the size limit, including the Salesforce WSDLs
Are WSDL files with imports supported?
No
Why would you set HTTP headers on a Web Service callout?
To set the value of a cookie in an authorization header
inputHttpHeaders_x is used for callout and outputHttpHeaders can be used to read the HTTP response headers returned after an HTTP request
When importing an external WSDL, what is generated in SFDC?
Successful importation of an external WSDL will generate an Apex stub (proxy) class
Use the stub instance to
- setup your authorization credentials for the external service
- make external service method calls
How do you expose an Apex class as a REST service
Define your class as global and define methods as global static. Add the annotations to the class and methods
The Apex class should have the @RestResource annotation. Similarly, you can add annotations to the class methods to expose them through REST
example: @RestResource(urlMapping='/Account/*') global with sharing class MyRestResource { @HttpGet global static Account getRecord() { // Add your code } }
Which annotation is used to specify a RESTful Web service method that will delete a specified resource?
@httpDelete deletes the specified resource
Which annotation is used to specify a RESTful Web service method that will return a specified resource?
@httpGet reads or retrieves records
Which annotation is used to specify a RESTful Web service method that will update a specified resource?
@HttpPatch updates fields in existing records
@HttpPut can also be used to update a existing records or create records
Which annotation is used to specify a RESTful Web service method that will create a specified resource?
@HttpPost creates a new record
@HttpPut can also be used to create records (as well as updating them)
Which annotation is used to specify a RESTful Web service method that will create or update a specified resource?
@HttpPut creates a new resource or updates the specified resource.
The RestContext object cointains which two Rest objects?
RestContext object cointains the RestRequest and RestResponse objects
Why do @HttpGet or @HttpDelete annotations not have any parameters?
This is because GET and DELETE requests do not have a body and hence do not need serialization
What type of parameters are used in Apex REST methods?
Use user-defined types for parameters in Apex REST methods
Which formats are used to represent resources for Apex REST Web Services?
JSON and XML formats are used to represent resources.
How do you invoke a REST-based webservice?
Through an appropriate HTTP request and a URL which includes a location of the Salesforce server, an Apex REST service and a resource
for example:
https://instance.salesforce.com/services/apexrest/resourceName
Can you make an webservice callout when a WSDL has not been imported?
Yes, you can make callouts from Apex where you are not using WSDL. It is also possible to access external Web Services using HTTP callouts without the associated infrastructre or requirement of WSDL or SOAP.
You can send HTTP requests, such as GET, POST and PUT and also handle responses returned by these requests
Which XML class is used to read through XML responses returned from callouts
XMLStreamReader
It enables foward, read-only access to XML data returned from an HTTP callout