Salesforce Integration Patterns & Best Practices

Join us to learn about different Salesforce integration Patterns & Best Practices. In this session, we will talk about different Integration patterns like request and reply/response, Fire and forget, Batch Data Synchronization, Remote Call In, and Data Virtualization.

Why Integration

Salesforce can’t be a source of everything. It can be CRM or any Custom application. However, SAP can own Order Management or Inventory, an External system for sending emails, Other System for Payment, External Fleet Management, And possibilities are high that Salesforce would need to exchange data with these systems. Please check Salesforce Integration with External System post to learn about Integration.

Check out our Salesforce Integration Guide.

Firewall, Proxy and Reverse Proxy

Before integrating anything with Salesforce, as per Architect, it is necessary which system components are important for security and may impact with integration pattern to be used.

1. Firewalls : It controls and protects Malicious Traffics. Firewall can be hardware or software based.

2. Proxy aka Forward Proxy : Proxy normally configured in your browser or systems like VsCode, data loader, eclipse to hide your actual identity. Every outgoing request transmits through proxy server to make sure external systems unaware about your true origin and identity

3. Reverse Proxy : Its used by Web Servers and sits before it. It can server any purpose like authentication or perform security related stuff. Best example is Mulesoft where we can configure API proxy which is used to apply throttling, avoiding DoS attacks or applying SLA as per licenses provided to customer

Factors Affecting Pattern

  • Maintain same transaction : Does Salesforce need to perform anything on response ?
  • Synchronous vs Asynchronous : Is it business critical & response needs to be processed in real time or near real time ?
  • Message size : Is it small or large ?
  • Guaranteed delivery needed : What if external system is down ?
  • Contract first integration possibility : Can remote system follow Salesforce Contract ?
  • Declarative preferred : Do we want to integrate without writing any code in Salesforce ?

Salesforce Integration Patterns & Best Practices

At high level, there are five types of integration patterns in Salesforce

  1. Request and Reply
  2. Fire and Forget
  3. Batch Data Synchronization
  4. Remote Call In
  5. Data Virtualization

1. Request & Reply

Salesforce invokes a process on a remote system, waits for completion of that process, and then tracks state based on the response from the remote system. Let see what all option we have for request & reply.

External Services : Point & click based integration from Lightning Flow. External system should provide OpenAPI or Interagent schema. Only supports primitive datatypes

LWC or Visualforce calling external system : Salesforce enables you to consume WSDL and generate proxy classes. It also provides HTTP services using which we can perform GET, POST, PUT or Delete operations. A user can initiate operation from custom UI.

Trigger : We can make callout to external system on data change via trigger. However callout made must be asynchronous. This solution is not recommended for request and reply but better suited for Fire and Forget.

Batch Apex invoking external services : We can make callout to external system using Batch Apex. Execute method in Batch apex gets refresh governor limit every time however there are governor limits on total callout or time of callout in single transaction

2. Fire & Forget

Salesforce invokes a process in a remote system but doesn’t wait for completion of the process. Instead, the remote process receives and acknowledges the request and then hands off control back to Salesforce. We can do the same with following ways:

  • Process-driven platform events
  • Customization-driven platform events
  • Workflow-driven outbound message
  • Apex based Callouts

3. Batch Data Synchronization

Data stored in Lightning Platform is created or refreshed to reflect updates from an external system, and when changes from Lightning Platform are sent to an external system. Updates in either direction are done in a batch manner.

Change Data Capture : Salesforce publishes change events, which represents changes on records
Using ETL Tool : This tool connects to systems, extract data, transform in require target format and uploads using Bulk API or SOAP API
Manual Remote Calls : Salesforce or external system can call each other every time data is changed. However, it would cause huge ongoing traffic and should be avoided if possible

Batch Integration
Batch Integration

4. Remote Call-In

Data stored in Lightning Platform is created, retrieved, updated, or deleted by a remote system.

  • SOAP & Rest API
  • Apex based APIs

5. Data Virtualization

Salesforce accesses external data in real time. This removes the need to persist data in Salesforce and then reconcile the data between Salesforce and the external system

Data Virtualization
Data Virtualization

Salesforce integration Patterns & Best Practices Video

YouTube video

Further Learning

Don’t forget to check the Jitendra Udemy course on Mastering Salesforce DX (Modular Application Development Using Unlocked Packages). If you are new in Salesforce. Please check our free Salesforce Admin and Salesforce Developer training.

Amit Chaudhary
Amit Chaudhary

Amit Chaudhary is Salesforce Application & System Architect and working on Salesforce Platform since 2010. He is Salesforce MVP since 2017 and have 17 Salesforce Certificates.

He is a active blogger and founder of Apex Hours.

Articles: 473

4 Comments

  1. Hello Experts,

    I need your advice on testing the integration of third party Rest API from apex like below

    public class Testing {
    public final String clientId = ‘xxxxxxxxxxxx’;
    public final String clientSecret = ‘xxxxxxxxxx’;

    public String getD365Customer(){
    String reqbody = ‘grant_type=client_credentials&client_id=’+clientId+’&client_secret=’+clientSecret;
    Http h = new Http();
    HttpRequest req = new HttpRequest();
    req.setBody(reqbody);
    req.setMethod(‘POST’);
    req.setEndpoint(‘https://login.microsoftonline.com/tenant/oauth2/token’);
    HttpResponse res = h.send(req);
    deserializeResponse resp1 = (deserializeResponse)JSON.deserialize(res.getbody(),deserializeResponse.class);
    String atoken = resp1.access_token;
    System.debug(‘Access Token=========’ + atoken);
    //return atoken;

    Http http1 = new Http();
    HttpRequest req1 = new HttpRequest();
    req1.setEndpoint(‘https://dev-mca/data/Customers’);
    req1.setMethod(‘GET’);
    req1.setHeader(‘Authorization’,’Bearer ‘+atoken);
    HttpResponse res1 = http1.send(req1);
    System.debug(‘Response Body=========’ + res1.getBody());
    return res1.getBody();
    }
    public class deserializeResponse
    {
    public String token_type;
    public String expires_in;
    public String ext_expires_in;
    public String expires_on;
    public String not_before;
    public String resource;
    public String access_token;
    }}
    But I am getting the error like
    Line: 23, Column: 1
    System.UnexpectedException: java.lang.IllegalArgumentException: invalid start or end

    Not sure if I am missing something.

  2. Thank you for wonderful session.

    I am having multiple requirements and want to check feasibility of platform events.

    1. On Opportunity close I need to update multiple external applications Currently I am using multiple Batch APEX approach and running the batch in every 10 mins. While performing this API callouts need to generate JSON request with multiple fields on opportunity and opportunity child objects. In some of the cases external systems are updating my opportunity as callback using SF data API/composite API. Can I use platform event as Fire and forget to notify external systems and the call back will remains same as is?

    2. There are multiple future calls in opportunity process execution, Can I replace future calls with platform events?

    3. The current daily volume of cases is very huge around 75 K opportunities per day and I am using Enterprise edition org. Will platform event suitable for such high volume of cases per day.

  3. Gone through the blog post and I must, I am very impressed by the details mentioned in here. Salesforce integration is a complex process and I think this post will prove very helpful for those who are looking for Salesforce integration services.

Leave a Reply

Your email address will not be published. Required fields are marked *