Salesforce: Real-time integration using Apex callout
In my previous blog, we talked about how to create a Salesforce Real-time Integration with an Outbound Message. Another option is using the Apex Callout functionality. Apex callout enables you to make a call to an external Web service or send an HTTP request from Apex code and then receive the response using SOAP and WSDL, or HTTP RESTful services.
Before we look at different ways of performing Apex Callout, you should know the following:
- All remove sites needed to be registered in Setup > Security Controls > Remote Site Settings
- Do not exceed 10 callouts in one single Apex Transaction
- Do not exceed 60 seconds timeout in one single Apex Transaction
Now that we understand all the pre-requisites,here are the options:
Option #1: Apex Callout using Classes generated from WSDL
To do this, download the WSDL to your machine and upload to Salesforce by clicking the “Generate from WSDL” button.
All the Apex classes will be generated upon successful import. However, not all WSDLs are supported. It will fail if:
- The resulting Apex classes has more than 1 million characters
- The WSDL is using RPC encoding
- The WSDL file has multiple portType/services/bindings
- The WSDL is referring to an external schema
Option #2: Apex Callout using HttpRequest Class
If you are performing an Apex Callout to a REST service or the WSDL is not supported in Option #1. You can always write your own Apex class using the HttpRequest Class.