heroku / salesforce-bulk

Python interface to the Salesforce.com Bulk API
MIT License
207 stars 154 forks source link

Example for delete? #59

Closed IanQS closed 6 years ago

IanQS commented 6 years ago

My workflow is as follows:

1) upload data (through this package) 2) process on salesforces' end 3) get back results.

I'm getting the ID of the created objects from

results = bulk.get_batch_results(batch_id)

then iterating through that and appending to a list(listIds). Later, when I try to do step 3

newJob = bulk.create_delete_job("Custom_Obj__c")
newBatch = bulk.post_batch(newJob, iter(listIds))
bulk.wait_for_batch(newJob, newBatch)
bulk.close_job(newJob)
print("Successfully deleted all records that were uploaded")

I get the error of

salesforce_bulk.salesforce_bulk.BulkBatchFailed: Batch 7513F000000GpvjQAC of job 7503F0000002GXcQAM failed: InvalidBatch : The 'delete' batch must contain only ids

but as far as I know it is only IDs? Granted it's a list of IDs that I ran iter on but still.

alexoneill commented 6 years ago

Hey @IanQS!

You can do it similarly to the example create_insert_job at the bottom of the README. The following should work:

# Create the job
newJob = bulk.create_delete_job("Custom_Obj__c")

# Create a CSV representation of the data
objs = [dict(Id=sf_id) for sf_id in listIds]
csv_iter = CsvDictsAdapter(iter(accounts))

# Post the request and close it
newBatch = bulk.post_batch(newJob, csv_iter)
bulk.wait_for_batch(newJob, newBatch)
bulk.close_job(newJob)

# Notify the user
print("Successfully deleted all records that were uploaded")