function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Natasha Ali 3Natasha Ali 3 

First RESTful API integration HELP!!!

I'm completely new to development and I need to develop an integration between Salesforce and a third party service (BKSB). Salesforce needs to consume the REST API. 

I need to write a trigger that will make a callout when a status changes on the custom 'Placement__c' object from '8 - Offer Accepted' to '9 - Induction Booked'. I have the following code so far (asked another dev):
trigger PlacementTrigger on Placement (before update) {
 Map<Id,Placement__c> newPlacList1=new Map<Id,Placement__c>();
 Map<Id,Placement__c> oldPlacList2=new Map<Id,Placement__c>();
 List<Placement__c> newPlacementList=new List<Placement__c>();;
    if(Trigger.IsUpdate && Trigger.isbefore ){
 for(Id placId : newPlacList1.keySet()){
  if(oldPlacList2.get(placId).Status__c == '8 - Offer Accepted' &&
        newPlacList1.get(placId).Status__c == '9 - Induction Booked'){
To identify the correct user's data to GET from the BKSB, the unique identifier is the email address on the Salesforce record. How do I incorporate this so the correct record is chosen in BKSB?
And where do I go from the trigger?

ANY help is much appreciated!!
Many Thanks,
Hi Natasha,
Trigger is to capture the event do a callout to external system.
In the above trigger, you have to call the external Rest API. So to call the BKSB Rest API, you have to import the WSDL of BkSB into Salesforce, then it will create a Apex class. 
In the above trigger, call that apex class to connect and send the data to BKSB.

First do the below trailhead tutorial, so that you will get the good idea of apex callout.

Hi Natasha,

You will have to use future methods to make REST callout to the external system. Following is a code model for that:
trigger PlacementTrigger on Placement (before update) {
	if(Trigger.IsUpdate && Trigger.isbefore ){

//Trigger handler class
public with sharing class PlacementTriggerHandler(){
	public static void findInductionBookedPlacements(List<Placement__c>  newPlacList, Map<Id,Placement__c>  oldPlacMap){
		Set<Id> inductionPlacementIdSet=new Set<Id>();
		for(Placement__c plac : newPlacList){
			if(oldPlacMap.get(placId).Status__c == '8 - Offer Accepted' && plac.Status__c == '9 - Induction Booked')
		if(inductionPlacementIdSet.size() > 0){
			// call future method
			//As triggers cannot make callouts, we need to call an asynchronous future method to make the callout. 
			//As future methods can only accept primitive data types as parameters, we are passing a set of Ids for Placement records and not the list of records

// callout class
public with sharing class calloutSerive(){
	//future method to make the callout
	@future(callout = true)
	public static void makeCalloutBKSB(Set<Id> placementIdSet){
	//fetch the placement records using placementIdSet
	//Construct the Httprequest
	//Make callout
	//handle response

Please go through the Apex REST Callouts unit from : trailhead module. Also as far as uniquely identifying the records in BKSB is concerned, they should let you know the JSON format for the request. for example a sample JSON request may look like this:
"placmentList" :[    "placement":{
                                "email" : "",
                                "name" : "ajax",
                                "institute" : "XXX University"
                                "email" : "",
                                "name" : "zenon",
                                "institute" : "YYY University"
                                "email" : "",
                                "name" : "beta",
                                "institute" : "ZZZ University"

If this helps, please like and mark resolved.