Salesforce Integration Basic Details
I’ll explain with 3 scenarios:
-
Salesforce → External System (one-way)
-
External System → Salesforce (one-way)
-
Two-way (bi-directional)
And in between, I’ll clarify Named Credentials, Connected Apps, OAuth, Client Id/Secret, API key, etc.
๐น Step 1: Core Building Blocks in Salesforce Integrations
1. Named Credential
-
What it is:
A secure way in Salesforce to store external endpoint URL + authentication method (OAuth, Basic, API key).
So your Apex code doesn’t hardcode credentials. -
Why we use it:
✅ Centralized credential management
✅ No need to store username/password in code
✅ Auto handles token refresh (if OAuth) -
When to use:
Whenever Salesforce needs to call an external system.
2. Connected App
-
What it is:
A configuration in Salesforce that allows an external system to connect into Salesforce using OAuth. -
Why we use it:
✅ If an external system needs to call Salesforce APIs (REST, SOAP, Bulk)
✅ Provides Client Id + Client Secret -
When to use:
When external system → Salesforce (not needed for Salesforce → external).
3. OAuth, Client Id, Client Secret
-
OAuth: Protocol for secure access (token-based).
-
Client Id & Secret: Credentials given by Salesforce (via Connected App) or by external system (if Salesforce is calling them).
-
Why we use:
Needed for secure integrations where username/password or API key is not enough.
4. API Key / Basic Auth
-
API Key: External system gives you a key → you include it in header.
-
Basic Auth: Username + Password encoded in header.
-
✅ Easier but less secure. Use only for simple integrations.
๐น Step 2: Scenarios
✅ Scenario 1: Salesforce → External System (one-way)
๐ Example: Push Account data from Salesforce to Oracle API.
What we use here:
-
Named Credential → stores Oracle API endpoint + auth (OAuth or API key).
-
Apex Callout (HttpRequest) → sends JSON data.
What we do NOT use:
-
❌ Connected App (not needed, because external system is not calling Salesforce).
Steps:
-
Analyse requirement → What data → Frequency (real-time / batch) → Secure auth method.
-
Create Named Credential with Oracle API details.
-
Write Apex class with HTTP callout.
-
Trigger it on DML (insert/update) or use Batch/Queueable for bulk.
-
Test with Mock callouts.
Code Example (Best Practice with Named Credential):
๐ This code uses Named Credential → no credentials in Apex.
✅ Scenario 2: External System → Salesforce (one-way)
๐ Example: Oracle system pushes customer transactions into Salesforce.
What we use here:
-
Connected App → in Salesforce (so Oracle can log in securely).
-
OAuth + Client Id/Secret → external system uses this to get token.
-
Salesforce REST API → external system calls
/services/data/vXX.X/sobjects/Account.
What we do NOT use:
-
❌ Named Credential (not needed, because Salesforce is not making the callout).
Steps:
-
Create Connected App in Salesforce (OAuth enabled, API enabled).
-
Give Client Id + Client Secret to external system.
-
External system requests token (
/services/oauth2/token). -
External system calls Salesforce REST APIs with Bearer token.
-
Test with Postman first, then connect Oracle.
Sample External API Call to Salesforce (Postman or Oracle):
Then use token:
✅ Scenario 3: Two-way Integration (bi-directional)
๐ Example: Salesforce sends Accounts → Oracle; Oracle sends Transactions → Salesforce.
What we use here:
-
Salesforce → Oracle: Named Credential + Apex Callout
-
Oracle → Salesforce: Connected App + OAuth (Client Id/Secret)
So we use both:
-
Named Credential (outbound)
-
Connected App (inbound)
Steps:
-
Analyse flows (who sends what, when).
-
Create Named Credential (Salesforce outbound).
-
Create Connected App (Salesforce inbound).
-
Develop Apex callouts for outbound.
-
Oracle uses REST API for inbound.
-
Define error handling + retry strategy.
-
Add logging + Platform Events if async.
-
Write test classes with Mock responses.
๐น Step 3: Summary Table
| Direction | What to Use | Why |
|---|---|---|
| Salesforce → External | Named Credential + Apex Callout | Secure, no hardcoded creds |
| External → Salesforce | Connected App + OAuth (Client Id/Secret) | External system logs in securely |
| Two-way | Both | Outbound (Named Credential), Inbound (Connected App) |
๐ฅ Golden Rules:
-
Always prefer Named Credentials for outbound (never store secrets in Apex).
-
Always use Connected Apps + OAuth for inbound (never expose username/password).
-
Use API keys only if system doesn’t support OAuth.
-
Always log integration success/failure.
Comments