Salesforce Integration Basics: REST APIs, Platform Events and Named Credentials

A beginner's guide to Salesforce integration — inbound and outbound patterns, REST, SOAP and Bulk APIs, Apex callouts with Named Credentials, Apex REST services, Platform Events and Change Data Capture, authentication, error handling and how to choose the right approach — with code examples.

Quick Answer: Salesforce integrates in two directions. Outbound, Salesforce calls other systems through Apex callouts or External Services, with credentials stored safely in Named Credentials, or publishes Platform Events and Change Data Capture events. Inbound, other systems use Salesforce's REST, SOAP, Bulk and Composite APIs, or custom Apex REST services, authenticated through OAuth. Choosing the right pattern, handling errors and securing access matter more than any single technology.

Almost no Salesforce org stands alone. Leads arrive from websites, orders flow to an ERP such as SAP, payments are confirmed by gateways, invoices go to e-invoicing systems, and messages go out through SMS and WhatsApp providers. Integration is where many projects spend the most effort and where many problems surface, which is why integration skills are among the best-paid in the Salesforce ecosystem.

This guide explains the core patterns and tools, with short examples, so you can understand integration designs, contribute to them, and answer interview questions confidently.

Integration Patterns

Salesforce describes a set of standard integration patterns. Knowing them helps you discuss designs in a common language:

PatternDirectionExample
Request and replySalesforce calls out and waitsCheck payment status before confirming an enrolment
Fire and forgetSalesforce notifies, does not waitSend an event when an order is confirmed
Batch data synchronisationEither direction, scheduledNightly sync of customers with the ERP
Remote call-inExternal system calls SalesforceWebsite creates leads through the API
UI update on data changeSalesforce pushes changes outDashboard updates when a case changes
Data virtualisationSalesforce reads external data liveShow ERP invoices without copying them

Two questions decide most designs: does the caller need an immediate answer, and how much data is moving? Real-time needs push towards APIs and events; large volumes push towards batch and Bulk API.

Outbound: Salesforce Calling Other Systems

Named Credentials

A Named Credential stores an endpoint URL and the authentication settings for an external system, so code never contains passwords, tokens or hard-coded URLs. Under the current model, the authentication details live in a linked External Credential, and access is granted to users through permission sets. Changing an endpoint between sandbox and production becomes a configuration change rather than a code change.

Apex callouts

With a Named Credential in place, an Apex callout refers to it with the callout: prefix:

HttpRequest req = new HttpRequest();
req.setEndpoint('callout:Payment_Gateway/v1/orders/' + orderId);
req.setMethod('GET');
req.setTimeout(20000);

HttpResponse res = new Http().send(req);
if (res.getStatusCode() == 200) {
    Map<String, Object> body =
        (Map<String, Object>) JSON.deserializeUntyped(res.getBody());
    String status = (String) body.get('status');
} else {
    // log the failure and decide whether to retry
}

Callouts have limits — a maximum number per transaction and an overall timeout — and they cannot run after uncommitted DML in the same transaction. That is why callouts triggered by record changes usually run asynchronously in Queueable Apex, as covered in our Apex interview questions article. In tests, callouts are replaced with mock responses.

External Services

If an external API has an OpenAPI specification, External Services can import it and generate actions that admins use directly in Flow, with no Apex. For straightforward APIs this is often the fastest and most maintainable route.

Inbound: Other Systems Calling Salesforce

Standard APIs

The REST API is the default for reading and writing records with JSON over HTTP. The SOAP API remains common in older enterprise systems. Bulk API 2.0 handles large loads and extracts asynchronously in jobs, and the Composite API bundles several requests — create an account, then its contacts — into one call, saving API requests and round trips. All of them respect the calling user's permissions and sharing.

Custom Apex REST services

When an external system needs a business-specific endpoint rather than raw record access, developers build an Apex REST service:

@RestResource(urlMapping='/enrolments/*')
global with sharing class EnrolmentApi {
    @HttpGet
    global static Enrolment__c getEnrolment() {
        String enrolmentId =
            RestContext.request.requestURI.substringAfterLast('/');
        return [
            SELECT Id, Status__c, Batch__c
            FROM Enrolment__c
            WHERE Id = :enrolmentId
            WITH USER_MODE
        ];
    }
}

The external system calls this endpoint with an OAuth token. Keep such services thin, validate inputs, enforce sharing and user mode, and return clear error responses.

Authentication

External systems authenticate with OAuth 2.0 through a connected app or the newer external client apps, using flows such as JWT bearer or client credentials for system-to-system integration. Each integration should run as a dedicated integration user with only the permissions it needs, never as an administrator.

Event-Driven Integration

Platform Events

Platform Events let Salesforce and other systems publish and subscribe to business events without calling each other directly. Publishing an event in Apex is short:

Enrolment_Confirmed__e evt = new Enrolment_Confirmed__e(
    Enrolment_Id__c = enrolment.Id,
    Student_Phone__c = enrolment.Phone__c
);
Database.SaveResult result = EventBus.publish(evt);

Subscribers — a Flow, an Apex trigger, or an external system using the Pub/Sub API — react independently. The publisher does not need to know who is listening, which makes systems easier to change and more resilient when one of them is temporarily down.

Change Data Capture

Change Data Capture publishes an event whenever selected records are created, updated, deleted or undeleted, including the changed fields. It is the standard way to keep an external system, such as a data warehouse or ERP, in sync with Salesforce in near real time without polling.

Choosing the Right Approach

NeedUsual choice
Call an external API from SalesforceApex callout or External Services, with a Named Credential
External system reads or writes a few recordsStandard REST API
Load or extract large volumesBulk API 2.0
Several related operations in one callComposite API
Custom logic behind an endpointApex REST service
Notify other systems of business eventsPlatform Events
Stream record changes to other systemsChange Data Capture
Show external data without storing itSalesforce Connect with external objects
Many systems, complex transformationsMiddleware such as MuleSoft

Middleware platforms such as MuleSoft, which Salesforce owns, become worthwhile when many systems are involved, transformations are complex, or the same integration must be reused across several applications.

Error Handling and Reliability

Integrations fail: networks time out, external systems go down, data arrives in unexpected formats. Good designs plan for it. Log every failed call with enough detail to investigate. Retry transient failures with sensible limits and back-off, but not permanent ones such as validation errors. Make operations idempotent — use external IDs and upsert so that a repeated message does not create duplicates. Monitor API usage against your org's daily limits, and alert someone when an integration stops processing. Most integration incidents in production are discovered by users first; good monitoring changes that.

A common trap: creating records from an external system with insert instead of upsert. When the external system retries after a timeout, duplicates appear. Using an external ID field with upsert avoids this entirely.

A Worked Example: From Enrolment to Payment and WhatsApp

Consider a training institute running admissions in Salesforce. When a counsellor marks an enrolment as confirmed, three things must happen: the payment gateway must create a payment link, the student must receive the link on WhatsApp, and the finance ERP must receive the enrolment for invoicing.

A clean design publishes an Enrolment Confirmed Platform Event when the status changes. One subscriber, a Queueable Apex job, calls the payment gateway through a Named Credential, stores the returned link and payment reference on the enrolment, and publishes a second event when the link is ready. A Flow subscribed to that event calls the WhatsApp provider through an External Services action. Meanwhile, Change Data Capture on Enrolment streams the confirmed record to middleware that maps it into the ERP's format. When the gateway later reports a successful payment, it calls an Apex REST endpoint that updates the enrolment using the payment reference as an external ID.

No step waits on another system directly, failures are isolated and logged, retries do not create duplicates, and each piece can be changed without rewriting the rest.

Security Checklist for Integrations

Use a dedicated integration user per external system, with a minimal permission set and no administrator rights. Store every credential in Named Credentials and External Credentials, never in code, custom settings or documents. Prefer OAuth flows designed for server-to-server use, and rotate secrets and certificates on a schedule. Restrict connected or external client apps by IP range or policy where possible. Validate and sanitise every inbound payload. Grant external systems access only to the objects and fields they need. And review API usage and login history regularly; an unusual spike is often the first sign of a problem.

Testing Integrations

In Apex tests, real callouts are not allowed, so implement HttpCalloutMock to return realistic success and failure responses and assert how your code handles each. Test Apex REST services by setting up RestContext request objects in tests. Test Platform Event subscribers by publishing events in a test and delivering them before assertions. Beyond unit tests, run end-to-end tests in a sandbox against the external system's test environment, including timeouts, invalid data and repeated messages — the situations that cause most production incidents.

Integration in an Indian Context

Typical Salesforce integrations in Indian organisations include payment gateways for collections and refunds; SMS and WhatsApp providers for notifications; GST and e-invoicing systems, usually through the ERP; SAP or other ERPs for orders, pricing and invoices; telephony and contact-centre platforms; and lending or KYC verification services in financial services. Each brings its own authentication method and data format, so consistent patterns, Named Credentials and central logging pay off quickly.

Integration in Interviews

Expect questions such as: What is a Named Credential and why use it? Why can't you make a callout after DML? How would you send data to an ERP when an opportunity closes? REST versus Bulk API — when do you use each? What is the difference between Platform Events and Change Data Capture? How do you prevent duplicates from retries? How do you test callouts? Answering with a pattern name, a reason and a short example shows real understanding.

Our Salesforce course covers Apex, asynchronous processing, Named Credentials, APIs and Platform Events with hands-on integration exercises and interview preparation.

People Also Ask / FAQ

Do admins need to know integration?

Admins should understand the concepts, API limits, integration users and tools such as External Services and Platform Events in Flow. Building complex integrations is usually developer work.

What is the difference between Platform Events and Change Data Capture?

Platform Events carry business events you define and publish deliberately. Change Data Capture automatically publishes record changes for selected objects.

Is MuleSoft required for Salesforce integration?

No. Many integrations use native APIs, callouts and events. Middleware becomes valuable with many systems or complex transformations.

How are Salesforce API limits counted?

Orgs have a rolling 24-hour allowance of API requests that depends on edition and licences. Composite and Bulk APIs help reduce usage.

Can Salesforce integrate with SAP?

Yes, commonly — through APIs, events and middleware, with Salesforce handling customer-facing processes and SAP handling orders, invoices and inventory.

Learn Salesforce Integration Hands-On

Live classes online and in select cities across India Explore the Salesforce Course