simple_salesforce.bulk module

Classes for interacting with Salesforce Bulk API

class simple_salesforce.bulk.SFBulkHandler(session_id, bulk_url, proxies=None, session=None)[source]

Bases: object

Bulk API request handler Intermediate class which allows us to use commands,

such as ‘sf.bulk.Contacts.create(…)’

This is really just a middle layer, whose sole purpose is to allow the above syntax

__init__(session_id, bulk_url, proxies=None, session=None)[source]

Initialize the instance with the given parameters.

Arguments:

  • session_id – the session ID for authenticating to Salesforce

  • bulk_url – API endpoint set in Salesforce instance

  • proxies – the optional map of scheme to proxy server

  • session – Custom requests session, created in calling code. This

    enables the use of requests Session features not otherwise exposed by simple_salesforce.

submit_dml(object_name, dml, data, external_id_field=None, batch_size=10000, use_serial=False, bypass_results=False, include_detailed_results=False)[source]
Perform any DML operation on any custom or

standard object in Salesforce i.e. insert/upsert/update/delete

Required to put this function in this class due to error: TypeError: ‘SFBulkType’ object is not callable - this makes SFBulkType callable for this specific function

The main purpose of this function is to build customizable reporting functions and reduce code reuse in individual execution scripts mainly with pandas

Arguments:

  • object_name – SF object

  • dml – insert, upsert, update, delete

  • data – JSON formatted salesforce records.

Data is batched by 10,000 records by default. To pick a lower size pass smaller integer to batch_size. to let simple-salesforce pick the appropriate limit dynamically, enter batch_size=’auto’

  • batch_size – default to 10,000

  • use_serial – default: bool = False

  • bypass_results – default: bool = False,

  • include_detailed_results –default: bool = False,

  • external_id_field – unique identifier field for upsert operations.

class simple_salesforce.bulk.SFBulkType(object_name, bulk_url, headers, session)[source]

Bases: object

Interface to Bulk/Async API functions

__init__(object_name, bulk_url, headers, session)[source]

Initialize the instance with the given parameters.

Arguments:

  • object_name – the name of the type of SObject this represents,

    e.g. Lead or Contact

  • bulk_url – API endpoint set in Salesforce instance

  • headers – bulk API headers

  • session – Custom requests session, created in calling code. This

    enables the use of requests Session features not otherwise exposed by simple_salesforce.

delete(data, batch_size=10000, use_serial=False, bypass_results=False, include_detailed_results=False)[source]

soft delete records

Data is batched by 10,000 records by default. To pick a lower size pass smaller integer to batch_size. to let simple-salesforce pick the appropriate limit dynamically, enter batch_size=’auto’

Return type:

Iterable[Any]

hard_delete(data, batch_size=10000, use_serial=False, bypass_results=False, include_detailed_results=False)[source]

hard delete records

Data is batched by 10,000 records by default. To pick a lower size pass smaller integer to batch_size. to let simple-salesforce pick the appropriate limit dynamically, enter batch_size=’auto’

Return type:

Iterable[Any]

insert(data, batch_size=10000, use_serial=False, bypass_results=False, include_detailed_results=False)[source]

insert records

Data is batched by 10,000 records by default. To pick a lower size pass smaller integer to batch_size. to let simple-salesforce pick the appropriate limit dynamically, enter batch_size=’auto’

Return type:

Iterable[Any]

query(data, lazy_operation=False, wait=5)[source]

bulk query

Return type:

Iterable[Any]

query_all(data, lazy_operation=False, wait=5)[source]

bulk queryAll

Return type:

Iterable[Any]

submit_dml(function_name, data, external_id_field=None, batch_size=10000, use_serial=False, bypass_results=False, include_detailed_results=False)[source]

modular bulk dml operations - perform insert/upsert/update/delete on any standard and custom objects in Salesforce.

update(data, batch_size=10000, use_serial=False, bypass_results=False, include_detailed_results=False)[source]

update records

Data is batched by 10,000 records by default. To pick a lower size pass smaller integer to batch_size. to let simple-salesforce pick the appropriate limit dynamically, enter batch_size=’auto’

Return type:

Iterable[Any]

upsert(data, external_id_field, batch_size=10000, use_serial=False, bypass_results=False, include_detailed_results=False)[source]

upsert records based on a unique identifier

Data is batched by 10,000 records by default. To pick a lower size pass smaller integer to batch_size. to let simple-salesforce pick the appropriate limit dynamically, enter batch_size=’auto’

Return type:

Iterable[Any]

worker(batch, operation, wait=5, bypass_results=False, include_detailed_results=False)[source]

Gets batches from concurrent worker threads. self._bulk_operation passes batch jobs. The worker function checks each batch job waiting for it complete and appends the results.

Return type:

Iterable[Any]