Showing posts with label What is Salesforce Integration. Show all posts
Showing posts with label What is Salesforce Integration. Show all posts

Thursday, March 16, 2023

Understand Salesforce Integration and HTTP Methods

What is Salesforce Integration?

Salesforce integration is the process of merging the data and functionality of Salesforce with another application to provide users with a single unified experience. It allows you to provide your team with an ideal mix of features pertaining to both platforms.

These classes expose the HTTP request and response functionality.

Http Class: Use this class to initiate an HTTP request and response.

HttpRequest Class: Use this class to programmatically create HTTP requests like GET, POST, PATCH, PUT, and DELETE.

HttpResponse Class: Use this class to handle the HTTP response returned by HTTP.


Most common HTTP methods:

1. GET : The GET method is used to retrieve information from the given server using a given URI. Requests using GET should only retrieve data and should have no other effect on the data.

2. POST : A POST request is used to send data to the server and create the record.

3. PUT : PUT is used to send data to a server to create/update a resource. Replaces all the current representations of the target resource with the uploaded content.

4. PATCH : PATCH is used to update partial resources. For instance, when you only need to update one field of the resource, PUTting a complete resource representation might be cumbersome and utilizes more bandwidth.

5. HEAD : HEAD is almost identical to GET, but without the response body. HEAD transfers the status line and the header section only.

6. DELETE : The DELETE method deletes the specified resource.

7. OPTIONS : The OPTIONS method describes the communication options for the target resource. 


public class AuthCallout {
    public void basicAuthCallout(){
    HttpRequest req = new HttpRequest();
    req.setEndpoint('http://www.yahoo.com');
    req.setMethod('GET');
    // Specify the required user name and password to access the endpoint
    // As well as the header and header information
    String username = 'myname';
    String password = 'mypwd';
    Blob hValue = Blob.valueOf(username + ':' + password);
    String authorizationHeader = 'Basic ' +EncodingUtil.base64Encode(hValue);
    req.setHeader('Authorization', authorizationHeader);
    // Create a new http object to send the request object
    // A response object is generated as a result of the request
    Http http = new Http();
    HTTPResponse res = http.send(req);
    System.debug(res.getBody());
    }
 }


Please share the blog and leave a comment about your thoughts.
Click here for more blogs.

Mostly Viewed