Simple, Lightweight Integration - Textnotes

Simple, Lightweight Integration


Integrations allow Salesforce to communicate with external systems using APIs, events, and secure connections.

1) REST API (Simple, Lightweight Integration)

✔ Explanation

REST API is used when systems communicate using JSON over HTTP.

Best for mobile apps, web apps, lightweight services.

✔ Common REST Methods

MethodPurposeExample
GETFetch dataGet Account details
POSTCreate dataCreate Contact
PATCHUpdate dataUpdate Opportunity
DELETEDelete dataDelete record

✔ Example REST Call (Fetch Account)

Endpoint:


/services/data/v60.0/sobjects/Account/001XXXXXXXXXXXX

Response (JSON):


{
"Name": "HDFC Bank",
"Industry": "Banking",
"Rating": "Hot"
}

✔ When to Use

  1. Mobile apps
  2. Web applications
  3. Lightweight data exchange

2) SOAP API (XML-based Integration)

✔ Explanation

SOAP API uses XML messages.

Used in large enterprises requiring strict security and WSDL contracts.

✔ Key Features

  1. Strongly typed
  2. WSDL dependent
  3. Heavy payload

✔ SOAP Example (XML Request)


<soapenv:Envelope>
<soapenv:Body>
<query>
SELECT Name FROM Account
</query>
</soapenv:Body>
</soapenv:Envelope>

✔ When to Use

  1. Legacy systems (banks, insurance, healthcare)
  2. WSDL-based integrations

3) Apex Callouts (Salesforce → External System)

✔ Explanation

Apex can make REST/SOAP calls to external services.

✔ Simple REST Callout Example


HttpRequest req = new HttpRequest();
req.setEndpoint('callout:WeatherAPI');
req.setMethod('GET');

Http http = new Http();
HttpResponse res = http.send(req);

System.debug(res.getBody());

✔ Key Rule

Apex callouts must run in:

  1. Future methods
  2. Queueable
  3. Batch
  4. @AuraEnabled (async)

4) Named Credentials (Secure External Connections)

✔ Explanation

Named Credentials store:

  1. Endpoint URL
  2. Authentication (OAuth, Basic, API Key)

No need to hardcode authentication inside Apex.

✔ Example Usage in Apex


req.setEndpoint('callout:MyServiceApi');

Salesforce automatically adds authentication.

✔ Benefits

  1. Secure
  2. No hardcoded secrets
  3. Easy to maintain

5) External Services (Low-Code Integrations)

✔ Explanation

External Services allows declarative integrations (no Apex).

You register:

  1. Swagger/OpenAPI specs
  2. Then use them directly in Flows.

✔ Example Use Case

Integrate:

✔ Payment Gateway

✔ Shipping API

✔ GST Validation API

Used directly inside Flow Builder.

6) Platform Events (Event-Driven Integrations)

✔ Explanation

Platform Events send real-time notifications between systems.

They follow a publish–subscribe model.

✔ Use Cases

  1. Send Order updates to ERP
  2. Notify external apps on Opportunity Closed
  3. Real-time IoT tracking

✔ Example (Publish Event in Apex)


Order_Event__e event = new Order_Event__e(
OrderId__c = '12345',
Status__c = 'Shipped'
);
Database.SaveResult sr = EventBus.publish(event);

7) Change Data Capture (CDC)

✔ Explanation

CDC sends real-time “record change” notifications for standard and custom objects.

✔ Example Notifications

  1. Account created
  2. Contact updated
  3. Opportunity stage changed

✔ Subscriber Systems

  1. Kafka
  2. AWS
  3. MuleSoft
  4. Integration middleware

✔ When to Use

For real-time data sync between Salesforce → External Systems.

8) Webhooks (External System → Salesforce)

✔ Explanation

External system sends real-time data to Salesforce via REST API.

✔ Example Use Case

  1. Payment success callback
  2. SMS delivery status
  3. WhatsApp message reply

✔ Webhook Flow

External System → Salesforce REST Endpoint → Insert/Update record

✔ Best Practice

Create an Apex REST service to receive webhook.

9) Integration Patterns & Best Practices

✔ Core Patterns

  1. Request & Response
  2. Used for REST, SOAP
  3. Real-time response
  4. Fire & Forget
  5. Platform Events
  6. CDC
  7. No response required
  8. Batch Data Sync
  9. Nightly integrations
  10. Bulk API / Data Loader
  11. Remote Call-In
  12. External systems → Salesforce (REST/SOAP)
  13. UI Integration
  14. Salesforce Screen + External UI via iframe

✔ Best Practices

🔹 Security

  1. Always use Named Credentials
  2. Never hardcode passwords / endpoints
  3. Use OAuth 2.0 where possible

🔹 Governor Limits

  1. Use Future, Queueable, Batch apex
  2. Use continuation in LWC for long-running requests

🔹 Error Handling

  1. Retry mechanisms
  2. Log failures
  3. Use Platform Events for async retry

🔹 Performance

  1. Use Bulk API for large data
  2. Use Cacheable=true for GET calls