Skip to content

BulkJob Reference

Salesforce Bulk Job Module.

This module provides classes for managing Salesforce Bulk API 2.0 jobs, including query jobs and DML operation jobs. These classes act as wrappers around a bulk client instance to simplify job-specific operations.

SfBulkJobQuery

SfBulkJobQuery(sf_bulk, job_info)

Bases: _SfBulkJobBase

Manage a Salesforce Bulk API query job.

This class simplifies waiting for job status and retrieving results for a specific query job.

ATTRIBUTE DESCRIPTION
_sf_bulk

The Bulk API client instance used for API communication.

TYPE: SfBulk

id

The unique ID for the Bulk API job.

TYPE: str

info

A dictionary holding the latest metadata and status for the job, which is updated after waiting.

TYPE: dict[str, Any]

PARAMETER DESCRIPTION
sf_bulk

The Bulk API client instance.

TYPE: SfBulk

job_info

The initial job information from the API.

TYPE: dict

get_info

get_info()

Fetch the latest job information from Salesforce.

Updates self.info with the latest status.

RETURNS DESCRIPTION
dict[str, Any]

The latest job information dictionary.

wait

wait(interval=None)

Wait the job status until it reaches a terminal state.

The terminal states are 'JobComplete', 'Aborted', or 'Failed'. Updates self.info with the final job status.

PARAMETER DESCRIPTION
interval

The waiting interval in seconds. If None, the client's default is used.

TYPE: int | None DEFAULT: None

RETURNS DESCRIPTION
dict[str, Any]

The final job information dictionary.

get_results

get_results(format_type='dict')

Get the job results in the specified format.

PARAMETER DESCRIPTION
format_type

The desired output format.

TYPE: FormatType DEFAULT: 'dict'

RETURNS DESCRIPTION
ResultType

The query results.

SfBulkJob

SfBulkJob(sf_bulk, job_info)

Bases: _SfBulkJobBase

Manage a Salesforce Bulk API DML job (e.g., insert, update, delete).

Supports uploading CSV data, marking the upload as complete, waiting its status, and retrieving successful or failed records.

ATTRIBUTE DESCRIPTION
_sf_bulk

The Bulk API client instance used for API communication.

TYPE: SfBulk

id

The unique ID for the Bulk API job.

TYPE: str

info

A dictionary holding the latest metadata and status for the job, which is updated after waiting.

TYPE: dict[str, Any]

PARAMETER DESCRIPTION
sf_bulk

The Bulk API client instance.

TYPE: SfBulk

job_info

The initial job information from the API.

TYPE: dict

upload_data

upload_data(csv_data)

Upload CSV data to the job.

PARAMETER DESCRIPTION
csv_data

A string containing the data in CSV format.

TYPE: str

complete_upload

complete_upload()

Mark the job's data upload as complete.

This signals to Salesforce that all data has been uploaded and the job is ready for processing (transitions to 'UploadComplete' state).

get_info

get_info()

Fetch the latest job information from Salesforce.

Updates self.info with the latest status.

RETURNS DESCRIPTION
dict[str, Any]

The latest job information dictionary.

wait

wait(interval=None)

Wait the job status until it reaches a terminal state.

The terminal states are 'JobComplete', 'Aborted', or 'Failed'. Updates self.info with the final job status.

PARAMETER DESCRIPTION
interval

The waiting interval in seconds. If None, the client's default is used.

TYPE: int | None DEFAULT: None

RETURNS DESCRIPTION
dict[str, Any]

The final job information dictionary.

is_successful

is_successful()

Check if the job completed successfully.

RETURNS DESCRIPTION
bool

True if the job state is 'JobComplete', False otherwise.

has_failed_records

has_failed_records()

Check if the job has any failed records.

RETURNS DESCRIPTION
bool

True if the number of failed records is greater than 0.

is_failed

is_failed()

Check if the entire job failed.

RETURNS DESCRIPTION
bool

True if the job state is 'Failed', False otherwise.

is_aborted

is_aborted()

Check if the job was aborted.

RETURNS DESCRIPTION
bool

True if the job state is 'Aborted', False otherwise.

get_successful_results

get_successful_results(format_type='dict')

Get the successfully processed records.

PARAMETER DESCRIPTION
format_type

The desired output format.

TYPE: FormatType DEFAULT: 'dict'

RETURNS DESCRIPTION
ResultType

The successful records in the specified format.

get_failed_results

get_failed_results(format_type='dict')

Get the records that failed to process.

The results include error messages from Salesforce.

PARAMETER DESCRIPTION
format_type

The desired output format.

TYPE: FormatType DEFAULT: 'dict'

RETURNS DESCRIPTION
ResultType

The failed records in the specified format.

get_unprocessed_records

get_unprocessed_records(format_type='dict')

Get records that were not processed.

This typically occurs if the job is aborted or a batch fails before these records could be processed.

PARAMETER DESCRIPTION
format_type

The desired output format.

TYPE: FormatType DEFAULT: 'dict'

RETURNS DESCRIPTION
ResultType

The unprocessed records in the specified format.