Actions
The Salesforce connector spans 5 packages:
ballerinax/salesforceballerinax/salesforce.apexballerinax/salesforce.bulkballerinax/salesforce.bulkv2ballerinax/salesforce.soap
Available clients:
| Client | Purpose |
|---|---|
Client | REST API: record CRUD, SOQL/SOSL, metadata, reports, password management, batch, invocable actions. |
Apex Client | Execute custom Apex REST endpoints exposed by your Salesforce org. |
Bulk Client | Bulk API v1: manage jobs and batches for large-scale CSV/JSON/XML data operations. |
Bulk V2 Client | Bulk API v2: simplified ingest and query jobs for large-scale data loads. |
Soap Client | SOAP API: lead conversion using the Salesforce SOAP protocol. |
For event-driven integration, see the Trigger Reference.
Client
REST API: record CRUD, SOQL/SOSL, metadata, reports, password management, batch, and invocable actions.
Configuration
| Field | Type | Default | Description |
|---|---|---|---|
baseUrl | string | Required | Salesforce instance URL (e.g., https://your-instance.salesforce.com). |
auth | OAuth2RefreshTokenGrantConfig|OAuth2PasswordGrantConfig|OAuth2ClientCredentialsGrantConfig|BearerTokenConfig | Required | OAuth 2.0 configuration or bearer token. |
apiVersion | string | "59.0" | Salesforce REST API version. |
httpVersion | HttpVersion | HTTP_2_0 | HTTP protocol version. |
timeout | decimal | 60 | Request timeout in seconds. |
retryConfig | RetryConfig | () | Retry configuration for failed requests. |
secureSocket | ClientSecureSocket | () | SSL/TLS configuration. |
proxy | ProxyConfig | () | Proxy server configuration. |
Initializing the client
import ballerinax/salesforce;
configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string refreshToken = ?;
configurable string baseUrl = ?;
salesforce:Client salesforceClient = check new ({
baseUrl: baseUrl,
auth: {
clientId: clientId,
clientSecret: clientSecret,
refreshToken: refreshToken,
refreshUrl: "https://login.salesforce.com/services/oauth2/token"
}
});
Operations
Record CRUD
getById
Retrieves a record by its Salesforce ID.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
sobjectName | string | Yes | API name of the sObject (e.g., "Account"). |
id | string | Yes | The Salesforce record ID. |
returnType | typedesc<record {}> | No | Expected return type. |
Returns: returnType|error
Sample code:
record {} account = check salesforceClient->getById("Account", "0015g00000XXXXX");
Sample response:
{"Id": "0015g00000XXXXX", "Name": "Acme Corporation", "Industry": "Technology"}
getByExternalId
Retrieves a record using an external ID field.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
sobjectName | string | Yes | API name of the sObject. |
extIdField | string | Yes | The external ID field name. |
extId | string | Yes | The external ID value. |
returnType | typedesc<record {}> | No | Expected return type. |
Returns: returnType|error
Sample code:
record {} account = check salesforceClient->getByExternalId("Account", "External_Id__c", "EXT-001");
Sample response:
{"Id": "0015g00000XXXXX", "Name": "Acme Corp", "External_Id__c": "EXT-001"}
create
Creates a new record of the specified sObject type.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
sObjectName | string | Yes | API name of the sObject. |
sObject | record {} | Yes | Fields and values for the new record. |
Returns: CreationResponse|error
Sample code:
salesforce:CreationResponse res = check salesforceClient->create("Account", {
Name: "New Account",
Industry: "Technology"
});
Sample response:
{"id": "0015g00000YYYYY", "success": true, "errors": []}
update
Updates an existing record identified by its Salesforce ID.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
sObjectName | string | Yes | API name of the sObject. |
id | string | Yes | The Salesforce record ID to update. |
sObject | record {} | Yes | Fields and new values to apply. |
Returns: error?
Sample code:
check salesforceClient->update("Account", "0015g00000XXXXX", {
Industry: "Finance"
});
upsert
Creates or updates a record based on an external ID field.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
sObjectName | string | Yes | API name of the sObject. |
externalIdField | string | Yes | The external ID field name used to match records. |
externalId | string | Yes | The external ID value. |
sObject | record {} | Yes | Fields and values for the upsert. |
Returns: error?
Sample code:
check salesforceClient->upsert("Account", "External_Id__c", "EXT-001", {
Name: "Acme Corp Updated",
Industry: "Technology"
});
delete
Deletes a record by its Salesforce ID.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
sObjectName | string | Yes | API name of the sObject. |
id | string | Yes | The Salesforce record ID to delete. |
Returns: error?
Sample code:
check salesforceClient->delete("Account", "0015g00000XXXXX");
deleteRecordsUsingExtId
Deletes a record using an external ID field.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
sObjectName | string | Yes | API name of the sObject. |
externalId | string | Yes | The external ID field name. |
value | string | Yes | The external ID value. |
Returns: error?
Sample code:
check salesforceClient->deleteRecordsUsingExtId("Account", "External_Id__c", "EXT-001");
Query & Search
query
Executes a SOQL query and returns matching records as a stream.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
soql | string | Yes | A valid SOQL query string. |
returnType | typedesc<record {}> | No | Expected record type for results. |
Returns: stream<returnType, error?>|error
Sample code:
stream<record {}, error?> results = check salesforceClient->query(
"SELECT Id, Name FROM Account WHERE Industry = 'Technology'"
);
check from record {} account in results
do {
// process each account record
};
Sample response:
{"Id": "0015g00000XXXXX", "Name": "Acme Corp"}
search
Executes a SOSL search and returns matching records as a stream.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
sosl | string | Yes | A valid SOSL search string. |
returnType | typedesc<record {}> | No | Expected record type for results. |
Returns: stream<returnType, error?>|error
Sample code:
stream<record {}, error?> results = check salesforceClient->search(
"FIND {Acme} IN ALL FIELDS RETURNING Account(Id, Name)"
);
check from record {} item in results
do {
// process each search result
};
Metadata & Utilities
getApiVersions
Returns a list of all available Salesforce REST API versions.
Returns: Version[]|error
Sample code:
salesforce:Version[] versions = check salesforceClient->getApiVersions();
Sample response:
[{"label": "Winter '24", "url": "/services/data/v59.0", "version": "59.0"}]
getResources
Lists the resources available for the specified API version.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
apiVersion | string | Yes | API version string (e.g., "v59"). |
Returns: map<string>|error
Sample code:
map<string> resources = check salesforceClient->getResources("v59");
Sample response:
{"sobjects": "/services/data/v59.0/sobjects", "query": "/services/data/v59.0/query"}
getLimits
Returns the API limits information for your organization.
Returns: map<Limit>|error
Sample code:
map<salesforce:Limit> limits = check salesforceClient->getLimits();
Sample response:
{"DailyApiRequests": {"Max": 15000, "Remaining": 14998}}
getOrganizationMetaData
Retrieves metadata about the current Salesforce org.
Returns: OrganizationMetadata|error
Sample code:
salesforce:OrganizationMetadata meta = check salesforceClient->getOrganizationMetaData();
Sample response:
{"encoding": "UTF-8", "maxBatchSize": 200, "sobjects": []}
getBasicInfo
Gets basic metadata for a specific sObject type, including recent items.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
sobjectName | string | Yes | API name of the sObject. |
Returns: SObjectBasicInfo|error
Sample code:
salesforce:SObjectBasicInfo info = check salesforceClient->getBasicInfo("Account");
Sample response:
{"objectDescribe": {"name": "Account", "label": "Account", "keyPrefix": "001"}}
describe
Completely describes the individual metadata at all levels of the specified sObject.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
sObjectName | string | Yes | API name of the sObject. |
Returns: SObjectMetaData|error
Sample code:
salesforce:SObjectMetaData meta = check salesforceClient->describe("Account");
Sample response:
{"name": "Account", "label": "Account", "fields": [], "childRelationships": []}
getPlatformAction
Queries for actions displayed in the UI, given a user, a context, device format, and a record ID.
Returns: SObjectBasicInfo|error
Sample code:
salesforce:SObjectBasicInfo actions = check salesforceClient->getPlatformAction();
Sample response:
{"objectDescribe": {"name": "PlatformAction", "label": "Platform Action"}}
Deleted & Updated Records
getDeletedRecords
Retrieves the list of individual records that have been deleted within the given timespan.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
sObjectName | string | Yes | API name of the sObject. |
startDate | time:Civil | Yes | Start date of the timespan. |
endDate | time:Civil | Yes | End date of the timespan. |
Returns: DeletedRecordsResult|error
Sample code:
import ballerina/time;
salesforce:DeletedRecordsResult deleted = check salesforceClient->getDeletedRecords(
"Account",
{year: 2026, month: 4, day: 1, hour: 0, minute: 0},
{year: 2026, month: 4, day: 23, hour: 0, minute: 0}
);
Sample response:
{"deletedRecords": [{"id": "0015g00000XXXXX", "deletedDate": "2026-04-15T10:30:00.000+0000"}], "earliestDateAvailable": "2026-01-01T00:00:00.000+0000", "latestDateCovered": "2026-04-23T00:00:00.000+0000"}
getUpdatedRecords
Retrieves the list of individual records that have been updated within the given timespan.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
sObjectName | string | Yes | API name of the sObject. |
startDate | time:Civil | Yes | Start date of the timespan. |
endDate | time:Civil | Yes | End date of the timespan. |
Returns: UpdatedRecordsResults|error
Sample code:
import ballerina/time;
salesforce:UpdatedRecordsResults updated = check salesforceClient->getUpdatedRecords(
"Account",
{year: 2026, month: 4, day: 1, hour: 0, minute: 0},
{year: 2026, month: 4, day: 23, hour: 0, minute: 0}
);
Sample response:
{"ids": ["0015g00000XXXXX", "0015g00000YYYYY"], "latestDateCovered": "2026-04-23T00:00:00.000+0000"}
Reports
listReports
Returns a list of all reports available in the org.
Returns: Report[]|error
Sample code:
salesforce:Report[] reports = check salesforceClient->listReports();
Sample response:
[{"id": "00O5g000005XXXXX", "name": "Quarterly Sales Report", "url": "/services/data/v59.0/analytics/reports/00O5g000005XXXXX"}]
runReportSync
Executes a Salesforce report synchronously and returns the results.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
reportId | string | Yes | The ID of the report to run. |
Returns: ReportInstanceResult|error
Sample code:
salesforce:ReportInstanceResult results = check salesforceClient->runReportSync("00O5g000005XXXXX");
Sample response:
{"attributes": {"reportId": "00O5g000005XXXXX", "type": "Report"}, "hasDetailRows": true}
runReportAsync
Executes a Salesforce report asynchronously and returns the report instance metadata.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
reportId | string | Yes | The ID of the report to run. |
Returns: ReportInstance|error
Sample code:
salesforce:ReportInstance instance = check salesforceClient->runReportAsync("00O5g000005XXXXX");
Sample response:
{"id": "0LG5g000001XXXXX", "status": "Running", "requestDate": "2026-04-23T10:00:00.000+0000"}
listAsyncRunsOfReport
Lists all asynchronous run instances of a report.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
reportId | string | Yes | The ID of the report. |
Returns: ReportInstance[]|error
Sample code:
salesforce:ReportInstance[] instances = check salesforceClient->listAsyncRunsOfReport("00O5g000005XXXXX");
Sample response:
[{"id": "0LG5g000001XXXXX", "status": "Success", "requestDate": "2026-04-23T10:00:00.000+0000"}]
getReportInstanceResult
Retrieves the results of a specific asynchronous report run instance.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
reportId | string | Yes | The ID of the report. |
instanceId | string | Yes | The ID of the report instance. |
Returns: ReportInstanceResult|error
Sample code:
salesforce:ReportInstanceResult result = check salesforceClient->getReportInstanceResult("00O5g000005XXXXX", "0LG5g000001XXXXX");
Sample response:
{"attributes": {"reportId": "00O5g000005XXXXX", "type": "Report"}, "hasDetailRows": true}
deleteReport
Deletes a report by its ID.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
reportId | string | Yes | The ID of the report to delete. |
Returns: error?
Sample code:
check salesforceClient->deleteReport("00O5g000005XXXXX");
Password Management
isPasswordExpired
Checks whether a user's password has expired.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
userId | string | Yes | The Salesforce user ID. |
Returns: boolean|error
Sample code:
boolean expired = check salesforceClient->isPasswordExpired("0055g00000XXXXX");
Sample response:
false
resetPassword
Resets a user's password and returns the new auto-generated password.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
userId | string | Yes | The Salesforce user ID. |
Returns: byte[]|error
Sample code:
byte[] newPassword = check salesforceClient->resetPassword("0055g00000XXXXX");
Sample response:
[78, 101, 119, 80, 97, 115, 115]
changePassword
Changes a user's password to a specified new password.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
userId | string | Yes | The Salesforce user ID. |
newPassword | string | Yes | The new password value. |
Returns: error?
Sample code:
check salesforceClient->changePassword("0055g00000XXXXX", "NewSecureP@ss1");
Batch & Invocable Actions
batch
Executes a batch of up to 25 subrequests in a single API call.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
batchRequests | Subrequest[] | Yes | Array of subrequests to execute. |
haltOnError | boolean | No | If true, stops processing on first error. Defaults to false. |
Returns: BatchResult|error
Sample code:
salesforce:BatchResult batchResult = check salesforceClient->batch([
{method: "GET", url: "v59.0/sobjects/Account/0015g00000XXXXX"},
{method: "GET", url: "v59.0/sobjects/Contact/0035g00000YYYYY"}
]);
Sample response:
{"hasErrors": false, "results": [{"statusCode": 200, "result": {"Id": "0015g00000XXXXX"}}]}
getQuickActions
Returns the list of quick actions available for a given sObject.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
sObjectName | string | Yes | API name of the sObject. |
Returns: QuickAction[]|error
Sample code:
salesforce:QuickAction[] actions = check salesforceClient->getQuickActions("Account");
Sample response:
[{"label": "New Contact", "name": "NewContact", "type": "Create"}]
getInvocableActions
Lists the invocable actions available for a given sub-context.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
subContext | string | Yes | The sub-context for the invocable action (e.g., "standard"). |
returnType | typedesc<record {}> | No | Expected return type. |
Returns: returnType|error
Sample code:
record {} actions = check salesforceClient->getInvocableActions("standard");
Sample response:
{"actions": [{"label": "Send Email", "name": "emailSimple", "type": "INVOCABLEACTION"}]}
invokeActions
Invokes a specific action with the given payload.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
subContext | string | Yes | The sub-context for the invocable action. |
payload | record {} | Yes | The action request payload. |
returnType | typedesc<record {}> | No | Expected return type. |
Returns: returnType|error
Sample code:
record {} result = check salesforceClient->invokeActions("standard/emailSimple", {
inputs: [{emailBody: "Hello", emailSubject: "Test", emailAddresses: "[email protected]"}]
});
Sample response:
[{"actionName": "emailSimple", "isSuccess": true, "outputValues": {}}]
getNamedLayouts
Retrieves information about alternate named layouts for a given sObject.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
sObjectName | string | Yes | API name of the sObject. |
layoutName | string | Yes | The layout name. |
returnType | typedesc<record {}> | No | Expected return type. |
Returns: returnType|error
Sample code:
record {} layout = check salesforceClient->getNamedLayouts("Account", "AllFields");
Sample response:
{"layouts": [{"id": "00h5g000000XXXXX"}]}
Apex Client
Execute custom Apex REST endpoints exposed by your Salesforce org.
Configuration
| Field | Type | Default | Description |
|---|---|---|---|
baseUrl | string | Required | Salesforce instance URL. |
auth | OAuth2RefreshTokenGrantConfig|OAuth2PasswordGrantConfig|OAuth2ClientCredentialsGrantConfig|BearerTokenConfig | Required | OAuth 2.0 configuration or bearer token. |
httpVersion | HttpVersion | HTTP_2_0 | HTTP protocol version. |
timeout | decimal | 60 | Request timeout in seconds. |
Initializing the client
import ballerinax/salesforce.apex;
configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string refreshToken = ?;
configurable string baseUrl = ?;
apex:Client apexClient = check new ({
baseUrl: baseUrl,
auth: {
clientId: clientId,
clientSecret: clientSecret,
refreshToken: refreshToken,
refreshUrl: "https://login.salesforce.com/services/oauth2/token"
}
});
Operations
Apex REST
apexRestExecute
Sends a request to a custom Apex REST endpoint using the specified HTTP method. This single function replaces the individual get, post, put, patch, and delete methods from earlier versions.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
urlPath | string | Yes | The relative path of the Apex REST resource (e.g., "/MyEndpoint/"). |
methodType | http:Method | Yes | HTTP method: GET, POST, PUT, PATCH, or DELETE. |
payload | record {} | No | Request body payload. Defaults to {}. |
returnType | typedesc<record {}|string|int?> | No | Expected return type. |
Returns: returnType|error
Sample code:
import ballerina/http;
// GET request
record {} getResult = check apexClient->apexRestExecute("/MyApexEndpoint/", http:GET);
// POST request
record {} postResult = check apexClient->apexRestExecute("/MyApexEndpoint/", http:POST, {
accountId: "0015g00000XXXXX",
action: "process"
});
Sample response:
{"status": "success", "message": "Operation completed"}
Bulk Client
Bulk API v1: manage jobs and batches for large-scale CSV/JSON/XML data operations.
Configuration
| Field | Type | Default | Description |
|---|---|---|---|
baseUrl | string | Required | Salesforce instance URL. |
auth | OAuth2RefreshTokenGrantConfig|OAuth2PasswordGrantConfig|OAuth2ClientCredentialsGrantConfig|BearerTokenConfig | Required | OAuth 2.0 configuration or bearer token. |
httpVersion | HttpVersion | HTTP_2_0 | HTTP protocol version. |
timeout | decimal | 60 | Request timeout in seconds. |
Initializing the client
import ballerinax/salesforce.bulk;
configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string refreshToken = ?;
configurable string baseUrl = ?;
bulk:Client bulkClient = check new ({
baseUrl: baseUrl,
auth: {
clientId: clientId,
clientSecret: clientSecret,
refreshToken: refreshToken,
refreshUrl: "https://login.salesforce.com/services/oauth2/token"
}
});
Operations
Job Management
createJob
Creates a new Bulk API v1 job for the given operation and sObject.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
operation | Operation | Yes | Bulk operation type: INSERT, UPDATE, UPSERT, DELETE, or QUERY. |
sobj | string | Yes | API name of the sObject. |
contentType | JobType | Yes | Content type of the batch data: CSV, JSON, or XML. |
extIdFieldName | string | No | External ID field name (required for UPSERT). Defaults to "". |
Returns: BulkJob|error
Sample code:
bulk:BulkJob job = check bulkClient->createJob(bulk:INSERT, "Contact", bulk:CSV);
Sample response:
{"jobId": "7505g000005XXXXX", "jobDataType": "CSV"}
getJobInfo
Returns the current status and metadata of a job.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
bulkJob | BulkJob | Yes | The bulk job object returned from createJob. |
Returns: JobInfo|error
Sample code:
bulk:JobInfo jobInfo = check bulkClient->getJobInfo(job);
Sample response:
{"id": "7505g000005XXXXX", "operation": "insert", "object": "Contact", "state": "Open"}
closeJob
Closes an open Bulk API v1 job, signalling that no more batches will be added.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
bulkJob | BulkJob | Yes | The bulk job object to close. |
Returns: JobInfo|error
Sample code:
bulk:JobInfo closedJob = check bulkClient->closeJob(job);
Sample response:
{"id": "7505g000005XXXXX", "operation": "insert", "object": "Contact", "state": "Closed"}
abortJob
Aborts an open or in-progress Bulk API v1 job.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
bulkJob | BulkJob | Yes | The bulk job object to abort. |
Returns: JobInfo|error
Sample code:
bulk:JobInfo abortedJob = check bulkClient->abortJob(job);
Sample response:
{"id": "7505g000005XXXXX", "state": "Aborted"}
Batch Operations
addBatch
Adds a batch of records to an open Bulk API v1 job.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
bulkJob | BulkJob | Yes | The bulk job object. |
content | json|string|xml|string[][]|stream<string[], error?>|io:ReadableByteChannel | Yes | The batch payload in the format matching the job's content type. |
Returns: BatchInfo|error
Sample code:
string csvData = "FirstName,LastName,Email\nJohn,Doe,[email protected]\nJane,Doe,[email protected]";
bulk:BatchInfo batch = check bulkClient->addBatch(job, csvData);
Sample response:
{"id": "7515g000001XXXXX", "jobId": "7505g000005XXXXX", "state": "Queued"}
getBatchInfo
Returns the current status and metadata of a specific batch.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
bulkJob | BulkJob | Yes | The bulk job object. |
batchId | string | Yes | The ID of the batch. |
Returns: BatchInfo|error
Sample code:
bulk:BatchInfo batchInfo = check bulkClient->getBatchInfo(job, batch.id);
Sample response:
{"id": "7515g000001XXXXX", "jobId": "7505g000005XXXXX", "state": "Completed", "numberRecordsProcessed": 2, "numberRecordsFailed": 0}
getAllBatches
Returns all batches associated with a job.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
bulkJob | BulkJob | Yes | The bulk job object. |
Returns: BatchInfo[]|error
Sample code:
bulk:BatchInfo[] allBatches = check bulkClient->getAllBatches(job);
Sample response:
[{"id": "7515g000001XXXXX", "state": "Completed"}]
getBatchRequest
Retrieves the original request data submitted for a batch.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
bulkJob | BulkJob | Yes | The bulk job object. |
batchId | string | Yes | The ID of the batch. |
Returns: json|xml|string|error
Sample code:
json|xml|string request = check bulkClient->getBatchRequest(job, batch.id);
Sample response:
"FirstName,LastName,Email\nJohn,Doe,[email protected]"
getBatchResult
Retrieves the results of a completed batch.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
bulkJob | BulkJob | Yes | The bulk job object. |
batchId | string | Yes | The ID of the completed batch. |
Returns: json|xml|string|Result[]|error
Sample code:
json|xml|string|bulk:Result[] results = check bulkClient->getBatchResult(job, batch.id);
Sample response:
[{"id": "0035g00000XXXXX", "success": true, "errors": []}]
Bulk v2 client
Bulk API v2: simplified ingest and query jobs for large-scale data loads.
Configuration
| Field | Type | Default | Description |
|---|---|---|---|
baseUrl | string | Required | Salesforce instance URL. |
auth | OAuth2RefreshTokenGrantConfig|OAuth2PasswordGrantConfig|OAuth2ClientCredentialsGrantConfig|BearerTokenConfig | Required | OAuth 2.0 configuration or bearer token. |
httpVersion | HttpVersion | HTTP_2_0 | HTTP protocol version. |
timeout | decimal | 60 | Request timeout in seconds. |
Initializing the client
import ballerinax/salesforce.bulkv2;
configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string refreshToken = ?;
configurable string baseUrl = ?;
bulkv2:Client bulkV2Client = check new ({
baseUrl: baseUrl,
auth: {
clientId: clientId,
clientSecret: clientSecret,
refreshToken: refreshToken,
refreshUrl: "https://login.salesforce.com/services/oauth2/token"
}
});
Operations
Ingest Jobs
createIngestJob
Creates a Bulk API v2 ingest job for inserting, updating, upserting, or deleting records.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
payload | BulkCreatePayload | Yes | Ingest job configuration including object, operation, and lineEnding. |
Returns: BulkJob|error
Sample code:
bulkv2:BulkJob ingestJob = check bulkV2Client->createIngestJob({
'object: "Contact",
operation: "insert",
lineEnding: "LF"
});
Sample response:
{"jobId": "7505g000005YYYYY"}
addBatch
Uploads data to an open ingest job.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
bulkJobId | string | Yes | The ID of the open ingest job. |
content | string|string[][]|stream<string[], error?>|io:ReadableByteChannel | Yes | Data to upload (CSV string, 2D string array, stream, or byte channel). |
Returns: error?
Sample code:
string csvData = "FirstName,LastName,Email\nAlice,Smith,[email protected]";
check bulkV2Client->addBatch(ingestJob.jobId, csvData);
closeIngestJob
Marks an ingest job as ready to be processed.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
bulkJobId | string | Yes | The ID of the ingest job to close. |
Returns: BulkJobCloseInfo|error
Sample code:
bulkv2:BulkJobCloseInfo closedJob = check bulkV2Client->closeIngestJob(ingestJob.jobId);
Sample response:
{"id": "7505g000005YYYYY", "state": "UploadComplete"}
closeIngestJobAndWait
Closes an ingest job and returns a future that completes when the job finishes processing.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
bulkJobId | string | Yes | The ID of the ingest job. |
Returns: future<BulkJobInfo|error>|error
Sample code:
future<bulkv2:BulkJobInfo|error> jobFuture = check bulkV2Client->closeIngestJobAndWait(ingestJob.jobId);
bulkv2:BulkJobInfo jobInfo = check wait jobFuture;
Sample response:
{"id": "7505g000005YYYYY", "state": "JobComplete", "numberRecordsProcessed": 1, "numberRecordsFailed": 0}
getJobInfo
Returns the current status of a job.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
bulkJobId | string | Yes | The ID of the job. |
bulkOperation | BulkOperation | Yes | The operation type: INGEST or QUERY. |
Returns: BulkJobInfo|error
Sample code:
bulkv2:BulkJobInfo info = check bulkV2Client->getJobInfo(ingestJob.jobId, bulkv2:INGEST);
Sample response:
{"id": "7505g000005YYYYY", "operation": "insert", "object": "Contact", "state": "JobComplete"}
getJobStatus
Returns successful or failed results for a completed ingest job as a 2D string array.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
bulkJobId | string | Yes | The ID of a completed ingest job. |
status | Status | Yes | Result status: SUCCESSFUL_RESULTS or FAILED_RESULTS. |
Returns: string[][]|error
Sample code:
string[][] successRecords = check bulkV2Client->getJobStatus(ingestJob.jobId, bulkv2:SUCCESSFUL_RESULTS);
Sample response:
[["sf__Id", "sf__Created", "FirstName", "LastName", "Email"], ["0035g00000XXXXX", "true", "Alice", "Smith", "[email protected]"]]
getAllJobs
Lists all ingest jobs in the org.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
jobType | JobType? | No | Optional filter by job type. |
Returns: AllJobs|error
Sample code:
bulkv2:AllJobs allJobs = check bulkV2Client->getAllJobs();
Sample response:
{"done": true, "records": [{"id": "7505g000005YYYYY", "operation": "insert", "object": "Contact", "state": "JobComplete"}]}
abortJob
Aborts an in-progress job.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
bulkJobId | string | Yes | The ID of the job to abort. |
bulkOperation | BulkOperation | Yes | The operation type: INGEST or QUERY. |
Returns: BulkJobInfo|error
Sample code:
bulkv2:BulkJobInfo aborted = check bulkV2Client->abortJob(ingestJob.jobId, bulkv2:INGEST);
Sample response:
{"id": "7505g000005YYYYY", "state": "Aborted"}
deleteJob
Deletes a completed or aborted job.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
bulkJobId | string | Yes | The ID of the job to delete. |
bulkOperation | BulkOperation | Yes | The operation type: INGEST or QUERY. |
Returns: error?
Sample code:
check bulkV2Client->deleteJob(ingestJob.jobId, bulkv2:INGEST);
Query Jobs
createQueryJob
Creates a Bulk API v2 query job to export records using SOQL.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
payload | BulkCreatePayload | Yes | Query job config containing operation and query fields. |
Returns: BulkJob|error
Sample code:
bulkv2:BulkJob queryJob = check bulkV2Client->createQueryJob({
operation: "query",
query: "SELECT Id, Name, Email FROM Contact WHERE CreatedDate = TODAY"
});
Sample response:
{"jobId": "7505g000005ZZZZZ"}
createQueryJobAndWait
Creates a query job and returns a future that completes when the job finishes.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
payload | BulkCreatePayload | Yes | Query job config containing operation and query fields. |
Returns: future<BulkJobInfo|error>|error
Sample code:
future<bulkv2:BulkJobInfo|error> queryFuture = check bulkV2Client->createQueryJobAndWait({
operation: "query",
query: "SELECT Id, Name FROM Account"
});
bulkv2:BulkJobInfo queryInfo = check wait queryFuture;
Sample response:
{"id": "7505g000005ZZZZZ", "state": "JobComplete", "numberRecordsProcessed": 100}
getQueryResult
Retrieves results from a completed query job as a 2D string array.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
bulkJobId | string | Yes | The ID of the completed query job. |
maxRecords | int? | No | Maximum number of records to return per request. |
Returns: string[][]|error
Sample code:
string[][] resultRows = check bulkV2Client->getQueryResult(queryJob.jobId, maxRecords = 1000);
Sample response:
[["Id", "Name", "Email"], ["0035g00000XXXXX", "Alice Smith", "[email protected]"]]
getAllQueryJobs
Lists all query jobs in the org.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
jobType | JobType? | No | Optional filter by job type. |
Returns: AllJobs|error
Sample code:
bulkv2:AllJobs allQueryJobs = check bulkV2Client->getAllQueryJobs();
Sample response:
{"done": true, "records": [{"id": "7505g000005ZZZZZ", "operation": "query", "state": "JobComplete"}]}
Soap Client
SOAP API: lead conversion using the Salesforce SOAP protocol.
Configuration
| Field | Type | Default | Description |
|---|---|---|---|
baseUrl | string | Required | Salesforce instance URL. |
auth | OAuth2RefreshTokenGrantConfig|OAuth2PasswordGrantConfig|OAuth2ClientCredentialsGrantConfig|BearerTokenConfig | Required | OAuth 2.0 configuration or bearer token. |
httpVersion | HttpVersion | HTTP_2_0 | HTTP protocol version. |
timeout | decimal | 60 | Request timeout in seconds. |
Initializing the client
import ballerinax/salesforce.soap;
configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string refreshToken = ?;
configurable string baseUrl = ?;
soap:Client soapClient = check new ({
baseUrl: baseUrl,
auth: {
clientId: clientId,
clientSecret: clientSecret,
refreshToken: refreshToken,
refreshUrl: "https://login.salesforce.com/services/oauth2/token"
}
});
Operations
Lead Conversion
convertLead
Converts one or more leads into accounts, contacts, and optionally opportunities.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
payload | LeadConvert | Yes | Lead conversion configuration specifying the lead to convert and conversion options. |
Returns: ConvertedLead|error
Sample code:
soap:ConvertedLead result = check soapClient->convertLead({
leadId: "00Q5g000005XXXXX",
convertedStatus: "Closed - Converted",
doNotCreateOpportunity: false,
opportunityName: "Acme Opportunity"
});
Sample response:
{"leadId": "00Q5g000005XXXXX", "accountId": "0015g00000XXXXX", "contactId": "0035g00000XXXXX", "opportunityId": "0065g00000XXXXX", "success": true}