# What integration patterns and best practices are recommended for connecting external ERP systems with Sales Cloud?

**Topic:** Sales Cloud · **Difficulty:** Medium · **Tags:** Sales Cloud, Integration, API Architecture

Read it on the site: https://www.forcechallenges.com/interview-questions/what-integration-patterns-and-best-practices-are-recommended-for-connecting-external-erp-systems-with-sales

## Answer

**Basics:** ERP systems own orders, invoices, inventory and pricing; Sales Cloud owns accounts, opportunities and quotes. Integration keeps them aligned. The Salesforce Architects pattern catalog names the options: Remote Process Invocation (request and reply, fire and forget), Batch Data Synchronization, Remote Call-In, UI Update Based on Data Changes, and Data Virtualization.

**How it works:**
1. Define system of record per entity and field.
2. Add an External ID field on Account/Product/Order for keying (ERP_Id__c).
3. Outbound events: change data capture or platform events, consumed by middleware or a subscriber, which calls the ERP.
4. Inbound updates: ERP or middleware calls REST/Bulk API with upsert by External ID.
5. Real-time lookups: Apex callouts via Named Credentials, or Salesforce Connect external objects over OData.
6. Observe: Event Monitoring and logging for auditing and error handling.

**Advanced / deep dive:** Prefer asynchronous, idempotent messages with retry and dead-letter handling. Use Bulk API 2.0 for large loads (parallel, retried by Salesforce) and Composite API to reduce call counts. Platform events and CDC have replay windows (commonly documented as 72 hours; verify for your event type) so subscribers can recover. Salesforce Connect avoids storage but depends on ERP availability and latency, and external objects have query and relationship limits and cannot do everything standard objects can. Use a middleware layer to decouple, transform and throttle. Secure with Named Credentials and External Credentials (OAuth, mutual TLS), an integration user with least privilege and IP restrictions.

**Code / config example:** Queueable callout using a Named Credential:
```apex
public class ErpPushJob implements Queueable, Database.AllowsCallouts {
    private List<Id> orderIds;
    public ErpPushJob(List<Id> ids) { orderIds = ids; }
    public void execute(QueueableContext ctx) {
        List<Order> orders = [SELECT Id, OrderNumber, TotalAmount FROM Order WHERE Id IN :orderIds];
        HttpRequest req = new HttpRequest();
        req.setEndpoint('callout:ERP_NC/orders');   // Named Credential holds auth
        req.setMethod('POST');
        req.setHeader('Content-Type', 'application/json');
        req.setBody(JSON.serialize(orders));
        HttpResponse res = new Http().send(req);
        if (res.getStatusCode() >= 300) { /* log and retry strategy */ }
    }
}
```
Inbound upsert: `PATCH /services/data/v60.0/sobjects/Account/ERP_Id__c/A-1001`.

**Hidden gotchas & must-remember points:**
- Limit of 100 callouts per transaction; 120 seconds cumulative timeout.
- You cannot make a callout after uncommitted DML in the same transaction.
- Always upsert on External ID to avoid duplicates.
- Daily API request limits are shared by all integrations.
- External objects do not store data, so reports and automation over them are restricted.
- Event Monitoring observes; it is not an integration mechanism.

**Best practice:** Use middleware, External IDs and async idempotent messaging, and document the system of record for every field.

---
Source: ForceChallenges · last updated 2026-11-02
