MuleSoft Solution: Pub/Sub API with Durable Subscription
Use the Salesforce Pub/Sub API (gRPC) with a durable subscription. Each subscriber maintains a replay ID cursor. When Mule reconnects, it automatically resumes from the last processed event.
- Configure MuleSoft to use gRPC Pub/Sub API instead of CometD Streaming API
- Store the last successful replay ID in a persistent store (database, Redis)
- On reconnect, resume from stored replay ID
- Set replay preset to CUSTOM and pass the stored replay ID
Salesforce Solution: Change Data Capture + Batch Recovery
Instead of Platform Events, use Change Data Capture. CDC provides a guaranteed replay buffer. Combine with a nightly batch job as safety net.
- Enable Change Data Capture on critical objects instead of Platform Events
- CDC retains all changes for 3 days minimum (up to 30 days with Event Relay)
- Build an Apex Batch job that runs hourly to sync any records updated in last 2 hours
- Batch job acts as reconciliation — catches anything Mule missed
MuleSoft Solution: Idempotency Header + Correlation ID
Add a custom header to every Mule → SF upsert request. Salesforce trigger checks this header and skips Platform Event publish if present.
- Mule sets HTTP header:
X-Integration-Source: MuleSoft - Mule sets unique correlation ID:
X-Correlation-Id: uuid - Salesforce trigger checks
Request.getCurrent().getHeader('X-Integration-Source') - If header equals 'MuleSoft', skip Platform Event publish
Salesforce Solution: Integration User + Bypass Flag
Create a dedicated Integration User for Mule. Trigger checks running user and skips Platform Event publish if it's the integration user.
- Create Salesforce user:
[email protected] - Grant this user a custom Permission Set:
Integration_User_Bypass - In trigger:
if (!FeatureManagement.checkPermission('Integration_User_Bypass')) { publishEvent(); } - All Mule API calls authenticate as this user
MuleSoft Solution: Chunking + Parallel Job Submission
Split the 5M records into 50 separate Bulk API jobs of 100k each. Submit them in parallel with max concurrency of 10 jobs at a time.
- Use DataWeave to split CSV into 100k-row chunks
- Submit each chunk as separate Bulk API job
- Use Scatter-Gather pattern with 10 parallel routes
- Poll each job independently until complete
- Aggregate failed records from all jobs into single retry file
Salesforce Solution: Apex Batch + Platform Events for Progress
Don't use Bulk API for data already in Salesforce. Use Apex Batch to process in chunks with progress tracking via Platform Events.
- Mule triggers an Apex REST endpoint to initiate batch job
- Apex Batch processes records in 200-record chunks (well under governor limits)
- Each chunk publishes a Progress Platform Event with success/failure count
- Mule subscribes to progress events and monitors completion
- No 24-hour timeout risk — Batch Apex has separate limits
MuleSoft Solution: Proactive Token Refresh with Interceptor
Implement a custom Mule interceptor that checks token expiry before each API call and refreshes proactively.
- Store token metadata:
{ access_token, issued_at, expires_in } - Before each SF API call, check:
if (now - issued_at > expires_in - 60s) refresh() - Refresh 60 seconds before actual expiry (safety buffer)
- Use OAuth refresh token flow:
POST /services/oauth2/tokenwithgrant_type=refresh_token - Update stored access_token and issued_at atomically
Salesforce Solution: Use Session ID with Connected App
Instead of OAuth access tokens (15-min expiry), use Salesforce Session ID which lasts 2+ hours (configurable up to 12 hours).
- Mule authenticates via SOAP login() call instead of OAuth
- SOAP login returns sessionId with much longer expiry
- Configure Session Settings in Salesforce: Setup → Session Settings → Timeout = 12 hours
- sessionId valid for entire session duration
WHERE LastModifiedDate > :lastSyncTime. Store last sync timestamp in persistent store. Reduces API consumption by 95%+.X-Correlation-Id header to all downstream calls. Log it in Salesforce triggers. Enables tracing request across both systems.<flow name="sync-accounts-to-salesforce"> <!-- 1. Generate correlation ID for tracing --> <set-variable variableName="correlationId" value="#[uuid()]" /> <!-- 2. Transform ERP data to Salesforce format --> <ee:transform> <ee:message> <ee:set-payload> %dw 2.0 output application/json --- payload map { Integration_Id__c: $.erpAccountId, Name: $.accountName, BillingStreet: $.address.street, AnnualRevenue: $.revenue as Number, // Correlation ID for idempotency check in SF Correlation_Id__c: vars.correlationId } </ee:set-payload> </ee:message> </ee:transform> <!-- 3. Upsert with External ID --> <try> <salesforce:upsert config-ref="Salesforce_Config" type="Account" externalIdFieldName="Integration_Id__c"> <salesforce:records>#[payload]</salesforce:records> </salesforce:upsert> <!-- 4. Log success --> <logger level="INFO" message="#['Upserted ' ++ sizeOf(payload) ++ ' accounts. Correlation: ' ++ vars.correlationId]" /> <!-- 5. Error handling --> <error-handler> <on-error-propagate type="SALESFORCE:CONNECTIVITY"> <!-- Transient error - send to retry queue --> <jms:publish destination="salesforce-retry-queue"> <jms:message> <jms:body>#[payload]</jms:body> <jms:properties> #[{ correlationId: vars.correlationId, retryCount: 0 }] </jms:properties> </jms:message> </jms:publish> </on-error-propagate> <on-error-propagate type="SALESFORCE:INVALID_DATA"> <!-- Permanent error - log to DLQ for manual review --> <db:insert config-ref="Database_Config"> <db:sql> INSERT INTO error_log (correlation_id, error_type, payload, timestamp) VALUES (:correlationId, :errorType, :payload, NOW()) </db:sql> <db:input-parameters> #[{ correlationId: vars.correlationId, errorType: 'VALIDATION_ERROR', payload: write(payload, 'application/json') }] </db:input-parameters> </db:insert> </on-error-propagate> </error-handler> </try> </flow>