SlideShare a Scribd company logo
Integrations
Inbound(REST and SOAP)
Outbound
Salesforce to Salesforce
 Create remote site settings first to allow the url to be accessible in salesforce.
Outbound Integration: How to invoke callouts
 1. From Setup, enter Remote Site Settings in the Quick Find box,
 2. Click Remote Site Settings.
 3. Click New Remote Site.
 4. Provide a name for the remote site
 5. Provide the URL for the remote site. This URL authorizes all subfolders for the endpoint, like
https://and https://th-apex-http-callout.herokuapp.com/path2. th-apex-http-
callout.herokuapp.com/path1
 6. Provide a description for the remote site / service.
 7. Click Save
To authorize remote callouts

public static HttpResponse makeGetCallout() {
 Http http = new Http();
 HttpRequest request = new HttpRequest();
 request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals');
 request.setMethod('GET');
 HttpResponse response = http.send(request);
 // If the request is successful, parse the JSON response.
 if (response.getStatusCode() == 200) {
 // Deserializes the JSON string into collections of primitive data types.
 Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
 // Cast the values in the 'animals' key as a list
 List<Object> animals = (List<Object>) results.get('animals');
 System.debug('Received the following animals:');
 for (Object animal: animals) {
 System.debug(animal);
 }
 }
 return response;
 }
Get the data using callouts using heroku endpoint
public static HttpResponse makePostCallout() {
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
request.setBody('{"name":"mighty moose"}');
HttpResponse response = http.send(request);
// Parse the JSON response
if (response.getStatusCode() != 201) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
} else {
System.debug(response.getBody());
}
return response;
}
Post the data using callouts
Inbound Integration:How to expose Apex classes
 SOAP :Protocol Neutral – accessible via HTTP, SMTP, TCP and other
application level protocols. Only XML. Requires WSDL
 REST: REStricted to http protocol,but can use JSON, XML, Atom and
others.
Soap Cases
Soap Cases
Rest Api sample code
Workbench rest api demo
//use this url to call from workbench /services/apexrest/devlight1973/GetCase/5009000001NxD87
Connected app usage
 package sfdc_rest;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URISyntaxException;
 import org.apache.http.client.methods.*;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.ParseException;
 import org.apache.http.util.EntityUtils;
 import org.apache.http.client.utils.URIBuilder;
 import org.apache.http.client.ClientProtocolException;
 import org.json.JSONObject;
 import org.json.JSONTokener;
 import org.json.JSONException;
 public class Main {
 static final String USERNAME = "narenrr@yahoo.com";
 static final String PASSWORD = "2WHVAUUcVWbxXMmKFQDEl1sgK0";
 static final String LOGINURL = "https://login.salesforce.com";
 static final String GRANTSERVICE =
 "/services/oauth2/token?grant_type=password";
Advanced example – JAVA rest api
 Generate enterprise WSDL
 Generate Class wsdl
 Enter user name /pwd/token
 Get session id and url prefix
 Invoke method with session id and correct endpoint url
How to expose webservice with SOAP
Main differences between WSDL
 Between two prod orgs
 One will be sender,other will be reciever of changes
 Cannot be done with developer org.
Salesforce to Salesforce
 Bad news salesforce does not allow callouts to be tested.
 Good News: Mock callouts to the rescue. Basically simulates a static
resource as target ,instead of the actual url.
 Purpose is to get code coverage of callouts
Testing callouts
Implement the callout
Actual class doing callout
Test class for the same
@isTest
private class CalloutClassTest {
@isTest static void testCallout() {
// Set mock callout class
Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator());
HttpResponse res = CalloutClass.getInfoFromExternalService();
// Verify response received contains fake values
String contentType = res.getHeader('Content-Type');
System.assert(contentType == 'application/json');
String actualValue = res.getBody();
String expectedValue = '{"example":"test"}';
System.assertEquals(actualValue, expectedValue);
System.assertEquals(200, res.getStatusCode());
}
}

More Related Content

What's hot (20)

PDF
Salesforce Identity: Connect and Collaborate Anywhere, Securely with Single S...
Perficient, Inc.
 
PDF
Two-Way Integration with Writable External Objects
Salesforce Developers
 
PDF
APIC/DataPower security
Shiu-Fun Poon
 
PPTX
What is an API?
Muhammad Zuhdi
 
PPTX
Practical Headless Flow Examples
Salesforce Admins
 
PPT
Spring Batch 2.0
Guido Schmutz
 
PPTX
Governor limits
Shivanath Devinarayanan
 
PDF
LWC Episode 3- Component Communication and Aura Interoperability
Salesforce Developers
 
PPTX
Secure Coding: Field-level Security, CRUD, and Sharing
Salesforce Developers
 
PPTX
Database in Android
MaryadelMar85
 
PDF
WEB DEVELOPMENT USING REACT JS
MuthuKumaran Singaravelu
 
PDF
REST APIs with Spring
Joshua Long
 
PPTX
API Development with Laravel
Michael Peacock
 
PPT
Ajax Ppt 1
JayaPrakash.m
 
PPTX
Rest API
Rohana K Amarakoon
 
PPT
Authentication services
Greater Noida Institute Of Technology
 
PPTX
Salesforce APIs
Samuel De Rycke
 
PPTX
Salesforce Developer Console ppt
Kuhinoor Alom
 
PPTX
What is Salesforce lighting explained
Roy Gilad
 
PPTX
Batch Apex in Salesforce
David Helgerson
 
Salesforce Identity: Connect and Collaborate Anywhere, Securely with Single S...
Perficient, Inc.
 
Two-Way Integration with Writable External Objects
Salesforce Developers
 
APIC/DataPower security
Shiu-Fun Poon
 
What is an API?
Muhammad Zuhdi
 
Practical Headless Flow Examples
Salesforce Admins
 
Spring Batch 2.0
Guido Schmutz
 
Governor limits
Shivanath Devinarayanan
 
LWC Episode 3- Component Communication and Aura Interoperability
Salesforce Developers
 
Secure Coding: Field-level Security, CRUD, and Sharing
Salesforce Developers
 
Database in Android
MaryadelMar85
 
WEB DEVELOPMENT USING REACT JS
MuthuKumaran Singaravelu
 
REST APIs with Spring
Joshua Long
 
API Development with Laravel
Michael Peacock
 
Ajax Ppt 1
JayaPrakash.m
 
Authentication services
Greater Noida Institute Of Technology
 
Salesforce APIs
Samuel De Rycke
 
Salesforce Developer Console ppt
Kuhinoor Alom
 
What is Salesforce lighting explained
Roy Gilad
 
Batch Apex in Salesforce
David Helgerson
 

Similar to Salesforce Integration using REST SOAP and HTTP callouts (20)

PDF
Webservices in SalesForce (part 1)
Mindfire Solutions
 
PDF
Caching the Uncacheable
danrot
 
PPTX
Performance #4 network
Vitali Pekelis
 
ODP
SCWCD 2. servlet req - resp (cap3 - cap4)
Francesco Ierna
 
ODP
Implementing Comet using PHP
King Foo
 
DOCX
Client server part 12
fadlihulopi
 
PDF
Java Libraries You Can’t Afford to Miss
Andres Almiray
 
PPTX
The Full Power of ASP.NET Web API
Eyal Vardi
 
PDF
XamarinとAWSをつないでみた話
Takehito Tanabe
 
PDF
Vladimir Vorontsov - Splitting, smuggling and cache poisoning come back
DefconRussia
 
PPT
Java Servlets
BG Java EE Course
 
PPTX
Spring MVC 3 Restful
knight1128
 
KEY
Using and scaling Rack and Rack-based middleware
Alona Mekhovova
 
PPTX
Rpi python web
sewoo lee
 
KEY
Building @Anywhere (for TXJS)
danwrong
 
PPT
Rapid java backend and api development for mobile devices
ciklum_ods
 
PDF
Server Side Swift: Vapor
Paweł Kowalczuk
 
ODP
Networking and Data Access with Eqela
jobandesther
 
PPTX
Design Summit - RESTful API Overview - John Hardy
ManageIQ
 
PPT
Php Asp Net Interoperability Rc Jao
jedt
 
Webservices in SalesForce (part 1)
Mindfire Solutions
 
Caching the Uncacheable
danrot
 
Performance #4 network
Vitali Pekelis
 
SCWCD 2. servlet req - resp (cap3 - cap4)
Francesco Ierna
 
Implementing Comet using PHP
King Foo
 
Client server part 12
fadlihulopi
 
Java Libraries You Can’t Afford to Miss
Andres Almiray
 
The Full Power of ASP.NET Web API
Eyal Vardi
 
XamarinとAWSをつないでみた話
Takehito Tanabe
 
Vladimir Vorontsov - Splitting, smuggling and cache poisoning come back
DefconRussia
 
Java Servlets
BG Java EE Course
 
Spring MVC 3 Restful
knight1128
 
Using and scaling Rack and Rack-based middleware
Alona Mekhovova
 
Rpi python web
sewoo lee
 
Building @Anywhere (for TXJS)
danwrong
 
Rapid java backend and api development for mobile devices
ciklum_ods
 
Server Side Swift: Vapor
Paweł Kowalczuk
 
Networking and Data Access with Eqela
jobandesther
 
Design Summit - RESTful API Overview - John Hardy
ManageIQ
 
Php Asp Net Interoperability Rc Jao
jedt
 
Ad

Recently uploaded (20)

PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
Executive Business Intelligence Dashboards
vandeslie24
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Executive Business Intelligence Dashboards
vandeslie24
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
Ad

Salesforce Integration using REST SOAP and HTTP callouts

  • 2.  Create remote site settings first to allow the url to be accessible in salesforce. Outbound Integration: How to invoke callouts
  • 3.  1. From Setup, enter Remote Site Settings in the Quick Find box,  2. Click Remote Site Settings.  3. Click New Remote Site.  4. Provide a name for the remote site  5. Provide the URL for the remote site. This URL authorizes all subfolders for the endpoint, like https://and https://th-apex-http-callout.herokuapp.com/path2. th-apex-http- callout.herokuapp.com/path1  6. Provide a description for the remote site / service.  7. Click Save To authorize remote callouts
  • 4.  public static HttpResponse makeGetCallout() {  Http http = new Http();  HttpRequest request = new HttpRequest();  request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals');  request.setMethod('GET');  HttpResponse response = http.send(request);  // If the request is successful, parse the JSON response.  if (response.getStatusCode() == 200) {  // Deserializes the JSON string into collections of primitive data types.  Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());  // Cast the values in the 'animals' key as a list  List<Object> animals = (List<Object>) results.get('animals');  System.debug('Received the following animals:');  for (Object animal: animals) {  System.debug(animal);  }  }  return response;  } Get the data using callouts using heroku endpoint
  • 5. public static HttpResponse makePostCallout() { Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals'); request.setMethod('POST'); request.setHeader('Content-Type', 'application/json;charset=UTF-8'); request.setBody('{"name":"mighty moose"}'); HttpResponse response = http.send(request); // Parse the JSON response if (response.getStatusCode() != 201) { System.debug('The status code returned was not expected: ' + response.getStatusCode() + ' ' + response.getStatus()); } else { System.debug(response.getBody()); } return response; } Post the data using callouts
  • 6. Inbound Integration:How to expose Apex classes  SOAP :Protocol Neutral – accessible via HTTP, SMTP, TCP and other application level protocols. Only XML. Requires WSDL  REST: REStricted to http protocol,but can use JSON, XML, Atom and others.
  • 10. Workbench rest api demo //use this url to call from workbench /services/apexrest/devlight1973/GetCase/5009000001NxD87
  • 12.  package sfdc_rest;  import java.io.IOException;  import java.io.InputStream;  import java.net.URISyntaxException;  import org.apache.http.client.methods.*;  import org.apache.http.impl.client.DefaultHttpClient;  import org.apache.http.HttpResponse;  import org.apache.http.HttpStatus;  import org.apache.http.ParseException;  import org.apache.http.util.EntityUtils;  import org.apache.http.client.utils.URIBuilder;  import org.apache.http.client.ClientProtocolException;  import org.json.JSONObject;  import org.json.JSONTokener;  import org.json.JSONException;  public class Main {  static final String USERNAME = "[email protected]";  static final String PASSWORD = "2WHVAUUcVWbxXMmKFQDEl1sgK0";  static final String LOGINURL = "https://login.salesforce.com";  static final String GRANTSERVICE =  "/services/oauth2/token?grant_type=password"; Advanced example – JAVA rest api
  • 13.  Generate enterprise WSDL  Generate Class wsdl  Enter user name /pwd/token  Get session id and url prefix  Invoke method with session id and correct endpoint url How to expose webservice with SOAP
  • 15.  Between two prod orgs  One will be sender,other will be reciever of changes  Cannot be done with developer org. Salesforce to Salesforce
  • 16.  Bad news salesforce does not allow callouts to be tested.  Good News: Mock callouts to the rescue. Basically simulates a static resource as target ,instead of the actual url.  Purpose is to get code coverage of callouts Testing callouts
  • 19. Test class for the same @isTest private class CalloutClassTest { @isTest static void testCallout() { // Set mock callout class Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator()); HttpResponse res = CalloutClass.getInfoFromExternalService(); // Verify response received contains fake values String contentType = res.getHeader('Content-Type'); System.assert(contentType == 'application/json'); String actualValue = res.getBody(); String expectedValue = '{"example":"test"}'; System.assertEquals(actualValue, expectedValue); System.assertEquals(200, res.getStatusCode()); } }