Salesforce Integration Bootcamp Notes
Salesforce Integration Bootcamp Notes
Salesforce Integration Bootcamp Notes
Bootcamp – Notes
Instructor: Aniket Kohale
Date: 13/05/2023
What is Integration?
Integration is the process of connecting different softwares systems and applications
together through the use of API’s (Application Programming Interface). It allows
different systems to communicate and share information with others, making it easier
to access and use data across different platforms.
Integration Terminologies?
1. API
2. API Endpoint
3. API Call or HTTP Callout or REST Callout
4. Resource
5. API Request
6. API Responses & Types (JSON/XML)
7. API Response Codes
8. Payload
9. API Methods
10. Query Parameters
11. Authentication
12. Web Services (REST & SOAP)
2
● API - Application Programming Interface is what API stands for. API is a set of
definitions and protocols that allow technology products and services to
communicate via the internet.
● API Call - The API call is simply the process of sending a request to your API
after setting up the right endpoints. Upon receiving your information, it is
processed, and you receive feedback. By entering your login and password into a
website and hitting ‘enter’, you made an API Call.
● API Endpoint - An endpoint is the end of a communication channel. When APIs
interact with other systems, each touchpoint of interaction is considered an
endpoint. For Example, It could be a server, or a database where a resource lives.
● Resource - An entity that can be represented by a URI and can be accessed
through an API. Resources can be anything from data (such as a list of users or a
single user's profile) to operations (such as creating or updating a resource).
● Request - An HTTP request sent by a client to a server to retrieve or modify data.
A request typically includes a method, a URI, and a set of headers and/or a body.
● Response - An HTTP response sent by a server to a client in response to a
request.
● Response Code - A numerical status code ) returned in an API response to
indicate the success or failure of a request. Common response codes include
200 (OK), 404 (Not Found), and 500 (Internal Server Error).
● Payload - The data sent in an API request or response, often in the form of a
JSON object.
● Method - The HTTP verb used in an API request, such as GET, POST, PUT, or
DELETE.
● Query Parameters - Key-value pairs that are ) added to the end of an API
endpoint URL to specify certain criteria or filters for the data being requested.
● Authentication - The process of verifying the identity of a client or user before
allowing them to access an API. This is often done using an API key or other
form of credentials.
● JSON - (JavaScript Object Notation) is a lightweight data-interchange format
based on a subset of JavaScript programming language standards. JSON has
the advantage that it is both easy for humans to read and write and for machines
to parse and generate. It is a format that is completely agnostic to languages and
uses conventions that are familiar to programmers of C-family languages.
3
Source: www.liquidweb.com
also lead to outdated or state data being served to clients if the cache is not
properly invalidated or refreshed.
● REST API’s can sometimes suffer from over fetching or under fetching, where the
client receives more or less data than it needs.
● In a REST API, adding a new field or endpoint requires a new version of the API.
This makes API evolution harder. Must use versioning to ensure that the existing
clients do not break. Needs to be supported and maintained.
● REST API’s typically require versioning when the shape of the data changes. In a
REST API, versioning can be implemented by using a different URL for each
version of the API.
HTTP Protocol
● HTTP Protocol - HTTP stands for HyperText Transfer Protocol.
Communication between client and web servers is done by sending HTTP
Requests and receiving HTTP Responses. HTTP Protocol is used to
perform CRUD operations (Create, Read, Update, Delete) by sending HTTP
requests with different HTTP methods. HTTP methods are also called
HTTP verbs.
Every HTTP request should have a URL or URI address and a method. The format of a
request message includes - A request-line, Zero or more header field(s) followed by
CRLF (Carriage Return, Line Feed), An empty line, A message-body (optional)
REST applications use HTTP methods like GET, POST, DELETE, PUT, etc., to do CRUD
operations.
GET Method
POST Method
PUT Method
PATCH Method
DELETE Method
GET Method - A GET request is used to request information from a resource such as a
website, a server or an API.
Example:
Since the GET method should never change the data on the resources and just read
them(ready only), it is considered a safe method.
Test an API with a GET Method - When we want to test an API, the most popular
method that we would Therefore, We expect to use is the GET method.
- If the resource is accessible, the API returns the 200 Status Code, which means
OK.
- Along with the 200 Status Code, the server usually returns a response body in
XML or JSON format. So, for example, we expect the [GET] /members endpoint
to return a list of members in XML or JSON.
- If the server does not support the endpoint, the server returns the 404 Status
Code, which means Not Found.
- If we send the request in the wrong syntax, the server returns the 400 Status
Code, which means Bad Request.
POST Method - It Created a new resource on the backend server. We send data to the
server in the request body.
Example:
8
Test an API with a POST Method - Since the POST method creates data, we must be
cautious about changing the data. Testing all the POST methods in APIs is highly
recommended. Here are some suggestions that we can do for testing APIs with POST
Method
- Create a resource with the POST method, and it should return the 201 Status
Code.
- Perform the GET method to check if it created the resource was successfully
created. You should get the 200 status code, and the response should contain
the created resource.
- Perform the POST method with incorrect or wrong formatted data to check if the
operation fails.
PUT Method - Using this, we can update an existing resource by sending the updated
data as the content of the request body to the server.
Example:
Test an API with a PUT Method - The PUT method is about modifying the entire
resources. Make sure to do the following operations.
- Send a PUT request fo the server many times, and it should always return the
same result.
9
- When the server completes the PUT request and updates the resource, the
response should come with 200 or 204 status codes.
- After the server completes the PUT request, make a GET request to check if the
data is updated correctly on the resource.
- If the input is invalid or has the wrong format, the resource must not be updated.
PATCH Method - Similar to PUT, PATCH updates a resource, but it updates data partially
and not entirely.
Example:
The PATCH method updates the provided fields of the employee entity. In general, this
modification should be in a standard format like JSON or XML.
Test an API with a PATCH Method - To test an API with PATCH method, follow the steps
for the testing API with the PUT and the POST Methods. Consider the following results
- Send a PATCH request to the server. The server will return the 2xx HTTP status
code, which means, the request is successfully received, understood, and
accepted.
- Perform the GET request and verify that the content is updated correctly.
- If the request payload is incorrect or ill-formatted, the operation must fail.
DELETE Method - The DELETE method deletes a resource. Regardless of the number of
calls, it returns the same result.
Example:
Most APIs always return the 200 status code even if we try to delete a deleted resource
but in some APIs, If the target data no longer exists, the method call would return a 404
status code.
10
Test an API with a DELETE Method - When it comes to deleting something on the
server, we should be cautious. We are deleting data, and it is critical. Then perform the
following actions
- Call the POST method to create a new resource. Never test DELETE with actual
data. For example, first, create a new employee and then fry to delete the
employee you just created.
- Make the DELETE request for a specific resource. For example, the request
[DELETE] /employees/{employee-id} deletes a employee with the specified
employee id.
- Call the GET method for the deleted employee, which should return 404, as the
resource no longer exists.
HTTP Request Methods - HTTP defines request methods to the desired action for a
resource Here are the 5 important request methods:
1XX Informational -
100 (Continue)
101 (Switching Protocols)
102 (Processing)
103 (Early Hints)
2XX Successful -
200 (0K)
201 (Created)
202 (Accepted)
203 (Non-Authoritative Information)
204 (No Content)
205 (Reset Content)
206 (Partial Content)
207 (Multi-Status)
208 (Already Reported)
226 (IM Used)
3XX Redirection -
System.JSONGenerator
System.JSONParser
● System.JSON - Contains methods for serializing Apex objects into JSON format
and deserializing JSON content that was serialized using the serialize method in
this class.
● System.JSONGenerator - Contains methods used to serialize objects into JSON
content using the standard JSON encoding.
● System.JSONParser - Represents a parser for JSON-encoded content.
REST callouts are based on HTTP. To understand how callouts work, it’s helpful to
understand a few things about HTTP. Each callout request is associated with an HTTP
method and an endpoint. The HTTP method indicates what type of action is desired.
15
HTTP Classes
// Instantiate a new HTTP request, specify the method (GET) as well as the
endpoint
HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('GET');
if(response.getStatusCode() != 201) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
} else {
System.debug(response.getBody());
}
Resources:
1. https://trailhead.salesforce.com/content/learn/modules/apex_integration_servic
es/apex_integration_rest_callouts
17
2. https://developer.salesforce.com/docs/atlas.en-us.224.0.apexcode.meta/apexc
ode/apex_callouts_http.htm
3. https://developer.salesforce.com/docs/atlas.en-us.224.0.apexcode.meta/apexc
ode/apex_classes_restful_http.htm
Source: www.apexhours.com
Use Action
@RestResource(urlMapping='/api/Account/*')
global with sharing class MyFirstRestAPIClass
{
@HttpGet
global static Account doGet() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String AccNumber =
req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE
AccountNumber = :AccNumber ];
return result;
}
@HttpDelete
global static void doDelete() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
19
String AccNumber =
req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE
AccountNumber = :AccNumber ];
delete result;
}
@HttpPost
global static String doPost(String name,String phone,String AccountNumber )
{
Account acc = new Account();
acc.name= name;
acc.phone=phone;
acc.AccountNumber =AccountNumber ;
insert acc;
return acc.id;
}
Postman Tool
https://www.postman.com/downloads/ & https://www.postman.com/
Postman is one of the most popular software testing tools which is used for API testing.
With the help of this tool, developers can easily create, test, share, and document APIs.
This tutorial will help in understanding why Postman is so famous and what makes it
unique when compared to other API testing tools. All the examples in this tutorial are
tested and can be imported in Postman.
● While using Postman, for testing purposes, one doesn't need to write any HTTP
client network code. Instead, we build test suites called collections and let
Postman interact with the API.
● In this tool, nearly any functionality that any developer may need is embedded.
This tool has the ability to make various types of HTTP requests like GET, POST,
PUT, PATCH, and convert the API to code for languages like JavaScript and
Python.
1) https://reqres.in/
2) http://dummy.restapiexample.com/
3) https://jsonplaceholder.typicode.com/
4) https://gorest.co.in/
5) https://restful-booker.herokuapp.com/
6) https://httpbin.org/#/
7) https://petstore.swagger.io/
8) https://fakerestapi.azurewebsites.net...
9) https://documenter.getpostman.com/vie...