Salesforce → Salesforce Mulesoft Integration
Project: Salesforce to Salesforce Listing & Image Sync
Description: Implementation of Mulesoft as a middleware in between two Salesforce
Instances.
Project Duration: June-25- Oct-25
Executive summary
Integrated Salesforce (advertisement and media data) with TARGET SALESFORCE SYSTEM to automate listing creation, updates, image uploads and deletions. The solution listens to Salesforce streaming events, enriches data via SOQL queries, transforms records into TARGET SALESFORCE SYSTEM payloads using DataWeave, and calls TARGET SALESFORCE SYSTEM REST APIs with OAuth2 token management. The integration reduced manual work, improved time-to-market for listings, and provided a reusable, secure API-led architecture for future channels.
Business problem
- Manual publishing and image uploads from Salesforce to TARGET SALESFORCE SYSTEM (error-prone and slow).
- Lack of reliable sync between Salesforce advertisement records and TARGET SALESFORCE SYSTEM listings.
- Need for retryable, observable communication with TARGET SALESFORCE SYSTEM APIs and secure token management.
High-level solution overview
Two System APIs were implemented following MuleSoft’s API-led connectivity model to isolate concerns:
1. SFDC System API
Listens to Platform Events (
Advertisement_Sync_Event__e)Executes SOQL queries on Advertisement, Vehicle, and ModelVariant objects
Transforms data into the required Target Salesforce payload format using DataWeave 2.0
Triggers the Target Salesforce System API for further operations
2. Target Salesforce System API
Manages listing lifecycle (create, update, delete)
Handles image uploads, image set operations, and token management
Uses Object Store for OAuth token caching
Implements retry (Until Successful) and error-handling mechanisms for reliability
Architecture (Conceptual)
Salesforce Platform Events —> SFDC Sys API (Replay Listener)
|– SOQL: Advertisement, Vehicle, ModelVariant
|– DataWeave transforms –> Target Salesforce Sys API (HTTP)
Target Salesforce Sys API:
– Retrieve / Cache Access Token (ObjectStore)
– Create / Update / Delete Listing
– Upload Images (multipart/form-data)
– Set images on listing (PUT)
Monitoring & Resilience:
– Until Successful retries
– Global Error Handler + Logging
– Observability via Logger
Key Components & Flows
SFDC System API
Target Salesforce System-impl-flow: Replay-channel listener for
Advertisement_Sync_Event__eExecutes SOQL queries to fetch
Advertisement__c,Vehicle__c, andModelVariant__crecordsUses DataWeave to prepare the listing payload
Triggers create/update/delete listing flows in the Target System
Manages image workflows by:
Querying
FileUpload__ccustom objectFetching binary data from ContentVersion
Posting to Target Salesforce System image endpoint
Updating Salesforce with returned content IDs
Target Salesforce System API
sync-listing flow determines the operation (create/update/delete)
create-listing: POST request to Target Salesforce System
update-listing: PUT request
delete-listing: DELETE request
upload-image: Builds multipart/form-data body and uploads image
set-imageids: Attaches image IDs to listings
get-token & cache-token: Fetches and stores OAuth tokens with expiry handling
Technical Highlights
Data Transformations: Advanced DataWeave 2.0 mapping from Salesforce SObjects to Target payloads
Token Management: Object Store caching with TTL; automatic token renewal on 401 errors
Resilience & Retries: External API calls wrapped in Until Successful scopes
Observability: Consistent Logger placement and a Global Error Handler for uniform error output
File Handling: Binary conversions from Salesforce ContentVersion.VersionData using
dw::core::BinariesAPI Configurations: Centralized HTTP request configurations for dynamic environments
Salesforce Connectors: Used
salesforce:replay-channel-listener,salesforce:query-all, andsalesforce:update
Responsibilities (Delivered by GAGSTEK)
Designed end-to-end API-led integration between Salesforce and Target Salesforce System
Implemented event-based ingestion with Replay Listener and SOQL enrichment
Developed System APIs for listing lifecycle and image operations
Implemented Object Store caching for optimized OAuth token usage
Added retries, error handling, and DataWeave transformations for reliability
Configured binary handling for image uploads
Built monitoring hooks compatible with Anypoint Monitoring
Results & Business Benefits
✅ Automated listing lifecycle (create, update, delete) eliminating manual errors
✅ Reduced time-to-market for listings
✅ Improved traceability with logs and Salesforce record updates
✅ Reusable APIs enabling rapid onboarding of new marketplaces
Challenges & Solutions
| Challenge | Solution |
|---|---|
| Token expiry & race conditions | Used Object Store for token caching; re-fetch token and retry on 401 |
| Binary image handling | Converted VersionData to multipart/form-data using DataWeave and Binaries module |
| Intermittent API errors | Wrapped REST calls in Until Successful with controlled backoff and retries |
| Idempotency in listing creation | Extracted listingId from Location header and stored in Salesforce |
Security & Governance
OAuth2 token-based authentication
Secure storage of client ID/secret and Salesforce credentials
Object Store TTL to prevent stale tokens
Audit logs for every critical flow for investigation and monitoring
Reusable Patterns & Recommendations
Continue using Object Store for any external OAuth provider integration
Apply Until Successful for idempotent API calls
Abstract HTTP request configs into properties files
Follow System → Process → Experience API separation for scalability
Client Testimonial
“GAGSTEK built a resilient, event-driven integration that automatically syncs Salesforce advertisements and images to Target Salesforce System24.
It manages OAuth tokens securely, handles retries for transient failures, converts and uploads image binaries, and writes back identifiers to Salesforce — providing a fully auditable, low-touch publishing pipeline reusable for other marketplaces.”
Appendix — Useful Snippets & Notes
1. Token Storage (Object Store)
<os:store key=”Target_SF_access_token” objectStore=”Object_store” />
2. Example: Building Multipart Payload for Image Upload (DataWeave 2.0)
%dw 2.0
import * from dw::core::Binaries
output multipart/form-data
—
{
parts: {
file: {
content: Binaries.fromBase64(payload.binary),
headers: {
“Content-Disposition”: “form-data; name=\”file\”; filename=\”” ++ payload.fileName ++ “\””,
“Content-Type”: payload.mimeType
}
}
}
}
3. Retry Pattern
<until-successful maxRetries=”3″ millisBetweenRetries=”3000″>
<!– http request –>
</until-successful>
4. Salesforce Replay Listener
<salesforce:replay-channel-listener
streamingChannel=”/event/Advertisement_Sync_Event__e”
replayOption=”ONLY_NEW”/>