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
Which XML class is used to create an XML document (or enables the writing of XML data)
XMLStreamWriter
What alternate classes (excluding the XMLStream classes) can be used for XML classes?
Document and XMLNode classes can be used as an alternate to XML classes?
What does JSON stand for?
JavaScript Object Notation
What is the purpose of the JSON class?
It provides methods to serialize and de-serialize JSON content
What is the purpose of the JSONGenerator class?
- Contains methods used to serialize Apex objects into JSON content
- Enables the generation of standard JSON-encoded content
What is the purpose of the JSONParser class
Represents a parser of JSON-encoded content that is returned from a web service call
What does REST stand for?
Stands for Representational State Transfer
Why would you use REST instead of SOAP calls?
REST builds on the existing structure of the web by using HTTP verbs such as POST, GET, PUT and DELETE to call services located at a specific URL without the need to delve into the intricacies of SOAP.
REST simply sends and receives XML or JSON data ver HTTP to or from a specific URL
What is the only method for the HTTP Class. Also provide the argument and return object
send() is the only method, which takes one HTTPRequest argument and returns and HTTPResponse
What are the methods for the HTTPRequest Class
setEndpoint() setBody() setHeader() setMethod() setClientCertificate()
getEndpoint()
getBody()
getHeader()
getMethod()
What are the methods for the HTTPResponse Class
getStatus() getStatusCode() getHeader() getHeaderKeys() getBody() getXMLStreamReader()
Which class can you use to encode or decode URL strings
EncodingUtil class
Which class can you use to enable access to external services that require encryption?
Crypto class
What 5 methods are available for the EncodingUtil Class?
base64Decode() base64Encode() convertToHex() urlDecode() urlEncode()
What 6 methods are available for the Crypto Class?
encrypt() decrypt() sign() generateMAC() generateDigest() generateAesKey()
What are two governor limits that there are for Asynchronous Methods ?
- The number of @future method calls per Apex invocation
- The maxium number of asynchronous Apex method executions per 24 hour period
What datatype parameters are allowed for an asynchronous method?
Must be primitive datatypes or collections of primitive data types.
Methods with the @future annotation cannot take _____ as arguments?
Methods with the @future annotation cannot take sObjects or objects as arguments?
The @future annotation cannot be used in ______ methods or constructors of Visualforce controllers?
The @future annotation cannot be used in getter/setter methods or constructors of Visualforce controllers
True or False:
You can call Web Services from external sources using SOAP Web Service Callouts?
True. You can call Web Services from external sources using SOAP Web Service Callouts
Which of the following guidelines are used for creating custom Web Services?
A) webservice methods must be static
B) webservice methods cannot be overloaded
C) A system-defined enum can be used anywhere in a webservice method
D) All classes that contain methods defied with the webService keyword must be declared as private
A) and B): The webservice methods must be static and cannot be overloaded
Identify the XMLStream classes that provide methods to read and write XML strings A) XMLStreamWriter B) XMLWriter C) XMLStreamReader D) XMLReader
A) and C): The XMLStreamWriter and XMLStreamReader classes provide methods to read and write XML strings
Identify the classes that you can use to make HTTP or RESTful callouts A) HTTP class B) HTTPRequest class C) HTTPServerRequest class D) HTTPResponse class E) HTTPServerResponse class
A) and B) and C). You can use HTTP class, HTTPRequest class and HTTPResponse class to make HTTP or RESTful callouts
An integration user makes a successful login() call via the SOAP API. What can be used in the SOAP header to provide server authorization for subsequent API requests? A) Named Credentials B) Session ID C) OAuth access toekn D) Security token
B) Session ID
Which of these statements is true for Lightning Connect?
A) No external data is imported into your Salesforce org
B) External data is read in real time when you request it
C) It can be used with any data source that supports OData 2.0.
D) All of the above
D) All of the above
Which of these is NOT an appropriate use case for Lightning Connect?
A) You want to integrate external data without writing custom code.
B) The external data is changing frequently.
C) You need to set up workflows and triggers for the external data.
D) You only need real-time access to a small fraction of the external data.
C) You need to set up workflows and triggers for the external data.
In which of these scenarios is ETL a better choice than Lightning Connect?
A) You need the external data to follow the sharing rules defined for your organization.
B) You want to generate reports and charts from the external data.
C) All of the above
C) All of the above
Which of these is NOT true about external objects?
A) They integrate with Salesforce APIs, Apex, Visualforce, and Chatter.
B) They can be related to other objects.
C) You can use them in formula fields.
D) They are automatically viewable in the Salesforce1 mobile app
C) You can use them in formula fields.
Which of the following statements is true about external callouts:
A) SOAP callouts use XML and may use a WSDL for code generation
B) HTTP callouts typically use JSON but can use XML as well
C) HTTP callouts are generally easier to work with than SOAP callouts
D) All of the above
D) All of the above
SOAP Web Services are commonly used for:
A) Simple, light weight services that are typically stateless
B) Public APIs that use HTTP and JSON
C) Enterprise apps that require a formal exchange format or stateful operations
D) No one uses SOAP any longer … it’s a four-letter word
C) Enterprise apps that require a formal exchange format or stateful operations
Which two authentication mechanisms does Apex REST and Apex SOAP support?
OAuth 2.0
Session ID
What Protocol and Data Format does the REST API require?
Protocol: REST
Data Format: JSON/ XML
What Protocol and Data Format does the SOAP API require?
Protocol: SOAP (WSDL)
Data Format: XML
What Protocol and Data Format does the Chatter REST API require?
Protocol: REST
Data Format: JSON/ XML
What Protocol and Data Format does the BULK API require?
Protocol: REST
Data Format: CSV/ JSON/ XML
What Protocol and Data Format does the Metadata API require?
Protocol: SOAP (WSDL)
Data Format: XML
What Protocol and Data Format does the Streaming API require?
Protocol: Bayeux
Data Format: JSON
What Protocol and Data Format does the Apex Rest API require?
Protocol: REST
Data Format: JSON/ XML, Custom
What Protocol and Data Format does the Apex SOAP API require?
Protocol: SOAP (WSDL)
Data Format: XML
What Protocol and Data Format does the Tooling API require?
Protocol: REST / SOAP (WSDL)
Data Format: JSON/ XML, Custom
What are the two declarations for using a certificate (with SOAP and HTTP)
SOAP: Assign the value to a clientCertName_x variable
ex: stub.clientCertName_x = ‘DocSampleCert’;
HTTP: setClientCertificateName using the certificate
ex: req.setClientCertificateName(‘DocSampleCert’);