MuleSoft Salesforce Connector
The Salesforce Connector is one of the most widely used connectors in MuleSoft. It lets your Mule application create, read, update, delete, and query Salesforce records, subscribe to Salesforce events, and invoke Apex classes. Almost every enterprise MuleSoft project includes at least one Salesforce integration.
Salesforce Connector Operations Overview
Operations Reference Diagram
Salesforce Connector
│
├── CRUD Operations
│ ├── Create → create one record
│ ├── Create Bulk → create many records at once
│ ├── Update → update one record by ID
│ ├── Upsert → insert if not exists, else update
│ ├── Delete → delete by record ID
│ └── Retrieve → get records by their IDs
│
├── Query Operations
│ ├── Query → run a SOQL query
│ ├── Query All → includes soft-deleted records
│ └── Query Single → returns first matching record
│
├── Event Operations
│ ├── Subscribe to Topic → real-time streaming via PushTopic
│ ├── Subscribe to Channel → Platform Events
│ └── Publish Platform Event
│
└── Advanced
├── Invoke Apex Rest → call custom Apex REST endpoint
└── Execute → run Salesforce Composite API
Setting Up Salesforce Connector Configuration
The Salesforce Connector supports multiple authentication types. The most common for integrations are Username/Password and OAuth 2.0 JWT Bearer (for production applications). Use Username/Password for development and testing.
Username/Password Connection Config
Configuration Name: Salesforce_Config
Connection Type: Username Password
Username: integration@mycompany.com
Password: ${sf.password}
Security Token: ${sf.securityToken}
(Salesforce requires the security token appended to the password
unless you whitelist your IP in Salesforce settings)
Test Connection: click to verify credentials are correct
SOQL — Salesforce Query Language
SOQL (Salesforce Object Query Language) looks like SQL but queries Salesforce objects instead of database tables. It follows the same SELECT-FROM-WHERE pattern.
SOQL Examples
// Get all open opportunities over $50,000: SELECT Id, Name, Amount, CloseDate, StageName FROM Opportunity WHERE StageName != 'Closed Won' AND StageName != 'Closed Lost' AND Amount > 50000 ORDER BY Amount DESC // Get contacts for a specific account: SELECT Id, FirstName, LastName, Email, Phone FROM Contact WHERE AccountId = '0011Q000023BxyzQAC' // Get records modified in the last 24 hours: SELECT Id, Name, LastModifiedDate FROM Account WHERE LastModifiedDate > LAST_N_HOURS:24
Query Operation in a Flow
Sync Leads from Salesforce to Database
[Scheduler: every 15 minutes]
│
▼
[Object Store: Retrieve watermark]
Key: "sf_lead_watermark"
Target: lastSync (default: "2000-01-01T00:00:00.000Z")
│
▼
[Salesforce: Query]
Query: SELECT Id, FirstName, LastName, Email, Status, CreatedDate
FROM Lead
WHERE CreatedDate > :lastSync
ORDER BY CreatedDate ASC
Parameters: { lastSync: #[vars.lastSync] }
│
▼ (payload = list of Lead records)
[Database: Bulk Insert / Upsert into local leads table]
│
▼
[Object Store: Store new watermark]
Key: "sf_lead_watermark"
Value: #[payload[-1].CreatedDate] (timestamp of last record)
Upsert Operation
Upsert is the most useful operation for sync flows. It inserts a record if it does not exist, and updates it if it does. You specify an external ID field — a field in Salesforce that uniquely identifies the record from the external system.
Upsert Flow: Sync Orders from ERP to Salesforce
Flow: syncERPOrdersToSalesforceFlow
[Database: SELECT * FROM erp_orders WHERE sync_status = 'pending']
│
▼
[Transform: map ERP order to Salesforce Order__c object]
%dw 2.0
output application/java
---
payload map (order) -> {
"ERP_Order_Id__c": order.ORDER_ID, // external ID field
"Account": { "ERP_Account_Id__c": order.ACCOUNT_ID },
"Amount__c": order.TOTAL_AMOUNT,
"Order_Date__c": order.ORDER_DATE as String {format: "yyyy-MM-dd"},
"Status__c": order.STATUS
}
│
▼
[Salesforce: Upsert]
Object Type: Order__c
External Id Field: ERP_Order_Id__c
Result: Each record either created or updated in Salesforce
Subscribe to Salesforce Platform Events
Platform Events are Salesforce's publish-subscribe messaging system. When something happens in Salesforce — a new order, an account change — Salesforce publishes a Platform Event. Your Mule application subscribes to it and reacts immediately without polling.
Platform Event Subscription Flow
Salesforce publishes:
Platform Event: Order_Shipped__e
{ "OrderId__c": "SF-ORD-001", "TrackingNumber__c": "FX123456" }
Mule application (event-driven, no polling needed):
[Salesforce: Subscribe to Channel]
Channel: /event/Order_Shipped__e
│ (fires every time Salesforce publishes this event)
▼
[Logger: "Order shipped: #[payload.OrderId__c]"]
│
▼
[HTTP Request: POST to customer-notification-api/notify]
{ "orderId": payload.OrderId__c, "tracking": payload.TrackingNumber__c }
│
▼
[Email Connector: send shipping confirmation to customer]
Bulk API for Large Data Volumes
The standard Salesforce API handles up to 10,000 records per batch. For larger volumes, use Salesforce Bulk API operations (Create Bulk, Update Bulk, Upsert Bulk). Bulk API processes records asynchronously inside Salesforce's infrastructure and supports millions of records.
[Database: SELECT * FROM migration_data]
(returns 500,000 records)
│
▼
[Salesforce: Create Bulk]
Object Type: Account
Batch Size: 10000 (Salesforce processes in groups of 10,000)
Salesforce processes all 500,000 records in batches internally.
Flow continues once all batches are submitted.
Error Handling for Salesforce Operations
Salesforce operations fail for several common reasons: invalid field values, missing required fields, record locking during high-concurrency periods, and governor limits exceeded. Handle each case specifically.
Error Handler for Salesforce Flow:
On Error Propagate: SALESFORCE:INVALID_FIELD
[Set Payload: {"error": "Invalid Salesforce field in request"}]
[HTTP status: 400]
On Error Propagate: SALESFORCE:LIMIT_EXCEEDED
[Logger: "Salesforce API limit reached. Retrying in 60 seconds."]
[Set Variable: shouldRetry = true]
On Error Propagate: SALESFORCE:INVALID_ID
[Set Payload: {"error": "Salesforce record not found"}]
[HTTP status: 404]
On Error Propagate: ANY
[Logger: "#[error.description]"]
[Set Variable: httpStatus = 500]
Handling the 10,000 Query Row Limit
SOQL queries return a maximum of 10,000 records by default. For larger datasets, add LIMIT and OFFSET to paginate through results, or use the Query All operation with auto-pagination enabled, which fetches all pages automatically and returns a complete list.
[Salesforce: Query] Query: SELECT Id, Name FROM Contact ORDER BY Id Fetch All Pages: true (connector handles pagination automatically) Automatically fetches page 1 (10,000 records), page 2 (10,000 records), etc. until all records retrieved.
