APEX Rest Callout in Salesforce Integration

APEX Rest Callout in Salesforce Integration

The Salesforce REST API allows you to integrate with Salesforce applications by using standard HTTP methods such as GET, POST, PUT, PATCH, DELETE, and HEAD. This API allows you to expose the data in your Salesforce application to third-party applications. 

Apex RestApi basically supports Oracle Rest Data Service endpoints as well as Apex application. 

There are common Http methods GET, POST, PUT, DELETE, and HEAD method to fetch the data either from salesforce org to third party or third party to salesforce. 

@HttpGet Method

It is used to read the data.

global static List<Tool__c> gettools() { 
        List< Tool__c> tools = [SELECT Name from Tools__c]; 
        return Tools__cs; 
    }

@HttpPost

It is used to create the data in salesforce org. 

global static String createnewtools(String Name) { 
        Tools__cw = new Tools__c(); 
        T.Name = Name; 
        insert w; 
        return '{"Status":"Done"}'; 
   }

dont miss out iconDon't forget to check out: All You Need to Know About Apex Test Class in Salesforce

@HttpPut

It creates or replaces the resource sent in the request body. 

global static String Tools__c(String Id, String NewName) { 
        Tools__c T = [ Select ID, Name from Tools__c__c where Id= :Id]; 
        T.Name = NewName; 
        update T; 
        return '{"Status":"Tools__c Updated"}'; 
    } 
}

@HttpDelete

It is used to delete a resource identified by a Url. 

global static String deleteWidgetById() { 
        String Id = RestContext.request.params.get('Id'); 
        String status = RestContext.request.params.get('status'); 
        List<Widget__c> w = [ Select ID from Widget__c where Id= :Id]; 
        delete w; 
        return '{"Status":"Deleted Widget"}' + status; 
    }

A request can have additional properties set in addition to the endpoint and HTTP method. A request, for example, might include headers that contain extra details about the request, such as the content type. POST requests, for instance, could include data to be sent to the service. In the next step, you will see an example of a POST request. A POST request is like having to submit form data by clicking a button on a web page. Instead of manually entering data on a web page, you send data as part of the body of the request with a callout.

dont miss out iconCheck out another amazing blog by Rishabh Shukla here: Navigation Service in LWC | All You Need to Know

Responses

Popular Salesforce Blogs