pythonsalesforcebulksimple-salesforce

simple-salesforce result from bulk insert/upsert


I am trying to match the output results to the input rows and from my test, it looks like bulk operation will return the result the same order but is it guaranteed?

input = [{json1},{json2},{json3},...]

sf = Salesforce(instance='<some instance>', session_id='<some session id>')

output = sf.bulk.some_table.upsert(json_data, 'key column', batch_size=1000, use_serial=False)


df1 = pd.json_normalize(input)
df2 = pd.json_normalize(output)

summary_df = pd.merge(input, output, left_index=True, right_index=True)

print(summary_df)

Solution

  • The documentation for the Bulk API appears to indicate that you can rely on the order of the result and Simple Salesforce shouldn't be returning in a different order (could potentially change but I don't see why the library would).

    Salesforce Documentation: https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/asynch_api_batches_failed_records.htm

    Track the record number for each result record. Each result record corresponds to a record in the batch. The results are returned in the same order as the records in the batch request. It's important to track the record number in the results so that you can identify the associated failed record in the batch request.