Apex Integration Flashcards

1
Q

What is API?

A
  • Application Programming Interface
  • Gets a request from the client, parses the request and tells the rest of the system what kind of operations to perform based on the result.
    • (it is the messenger that takes request and tells the system what you want to do and returns the response back to you)
  • They store resources, or individual record, using URI’s (Uniform Resource Identifiers)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Salesforce Connect?

A

allows us to establish a connection between our Salesforce org and an external database

Helpful because if we have a large amount of data in an outside system that we plan to continue using and don’t want to upload it to your org due to storage reasons or just for ease of use

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do we access URI’s?

A

We can access URIs at their corresponding Uniform Resource Locators (URLs), which are a part of the URI

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the different HTTP Methods? Which are idempotent?

A
  • GET
  • PUT
  • POST
  • PATCH
  • DELETE

Three of them are idempotent.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is meant by idempotent? Which methods are idempotent?

A
  • Being idempotent means that the end result of a set of duplicate requests with the same method to the same URL is independent of the number of duplicate requests
    • We CAN get different status codes in responses from idempotent methods

Tldr: you can request a method X amount of times and it’s not going to make a difference to what the end result is going to be

GET PUT DELETE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is GET?

A
  • idempotent method
  • Retrieves resource stored with the target URI
  • Because we’re only reading data, not changing it, it makes no difference if we make a GET request once or 100 times
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is PUT?

A
  • An idempotent method
  • Either creates a resource at the target URL, or updates (read:overwrites) the entirety of the resource at said URL if it already exists (usually update)
  • If you invoke a PUT API N times, the very first request will update the resource; the other N-1 requests will just overwrite the same resource state again and again – effectively not changing anything.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is POST?

A
  • NOT an idempotent method
  • Lets us create a resource at the target URI or update an existing resource
  • So POST is not idempotent because duplicate requests to the same URL will have compounding results
    • The first POST operation will create one resource, the second will create a second resource, etc.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the difference between POST and PUT?

A

POST is used to “create new” resource.

PUT is used to “insert, replace if it already exists”. 5”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is PATCH?

A
  • NOT an idempotent method
  • Allows us to update parts of existing resource, but doesn’t overwrite the entire resource
  • When making PATCH request, we only provide values for the fields that we want to change on the existing resource
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is DELETE?

A
  • An idempotent method
  • The first DELETE call will delete the resource with the specified URI
  • Because the resource no longer exists after the first DELETE call, we can make as many duplicate DELETE requests as we want
    • However, subsequent DELETE calls will give different status codes in their responses
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is HTTP Status Codes?

A

When we make a request using an HTTP method, the server will return a status code along with its response.

Status code represents the outcome of the operation.

Number Range: 100 - 599

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Tell me about the 1xx range status codes

A
  • Informational response:
    • Indicates request was received, continue process
  • 100: Continue
    • No errors processing the request so far
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Tell me about the 2xx range status codes

A
  • Sucess: request was successfully received, understood, and acceped
  • Common:
  • 200 - Code Message: Ok
    • Request was successful
  • 201- Created
      • resource was created
  • 204 - No Content
    • Request was successful but the body of response is empty (common response from DELETE call).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Tell me about the 3xx range status codes

A
  • Redirects - further action required
  • 300: Multiple Choice
    • Multiple responses need to choose one
  • 301: Moved Permanently
    • Resource URL has changed and new URL resource is included in the response body
  • 307: Temporary Redirect
    • Resource URL has changed temporarily, make request to the URI included in body
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Tell me about the 4xx range status codes

A
  • Client Side Errors - request contains bad syntax or canot be fulfilled
    • 400: Bad Request
      • Request had syntax error
    • 401: Unauthorized
      • Need to provide credentials
    • 403: Forbidden
      • Provided credentials but not authorized
    • 404: Page Not Found
      • Request sent to non-existent URL
17
Q

Tell me about the 5xx range status codes

A
  • Server Side Errors - failed to fulfil valid request
    • 500: Internal Server Error
      • Server didn’t know how to handle when processing our request
    • 502: Bad Gateway
      • Server made call to another service to get the information we requested, but that second service gave invalid response
18
Q

What is SOAP?

A

Simple Object Access Protocol, it is an XML-based communication architecture that allows different platforms and languages to communicate through HTTP requests.
SOAP services explain the ways to interact with them via WSDL - Web Service Description Language, a language based on XML

19
Q

What is Allowlisting?

A

Security feature that only allows trusted files, application, processes to run. Before we can make any request to an external site (doesn’t matter the kind of service), we need to allowlist it in our org.

  • Setup > Security > Remote SIte Settings and then click on New Remote Site
  • Give the URL of the site, give it an alias, and click Save
  • Once this is completed, we’re able to make an external callout to the service
20
Q

Mock Classes

A

Mock Classes act as fake objects that stand in for real instances of objects.

  • Apex test classes don’t let us make callouts to external services.
  • We need to create a response that mocks the one we would get as a result of the actual request
  • For SOAP callouts specifically, we achieve this by making a second test class that implements the WebServiceMock interface
  • must be global or public and define the doInvoke() method
21
Q

Test.setMock() method

A
  • Lets the system know which mock we’re
    using
  • Takes 2 parameters
  • First is the type of interface our mock
    implements(WebServiceMock.class when
    we’re testing SOAP callouts).
  • Second is the instance of class that
    implements this interface
22
Q

Salesforce SOAP API

A
  • Standard Out-Of-the-Box (OOB) SOAP API that we can use
  • Allows us to find duplicate records, execute queries, get information about objects and fields, perform DML operations, and more
23
Q

RESTful Services

A
  • Stands for Representational State Transfer
  • Set of guidelines for API architecture that has requirements like implementing a uniform interface across the service and the server being stateless
  • Using REST services generally tends to be easier and than using SOAP webservices
24
Q

Salesforce REST API

A
  • Standard REST API that they provide
  • Can use it to execute queries, get information about objects and fields, perform DML operations, and more
25
Q

OOB Salesforce APIs

A
  • Bulk API
  • Chatter REST API
  • User Interface API
  • Analytics REST API
  • Tooling API
  • Metadata API
  • Streaming API

OOB = out of box

26
Q

SOAP vs REST API

A

SOAP - protocol, uses service interface

REST - architectural style, uses URI