0

while trying to read the accounts table in salesforce by enabling the pk_chunking = True , getting an error as

salesforce_bulk.salesforce_bulk.BulkBatchFailed: Batch 7511M00000KiqGsQAJ of job None failed: None

I looked at the salesforce monitoring and there are 11 batches created by the pk_chunking and all the batches except the above case have the results and their requests look like

select Id from Account where Id >='' and Id<'' " 

Here is the code I wrote:

table_names = ['Account','table1']
bulk = connect_sfdc_bulk('prod')
for x in table_names:
    job = bulk.create_query_job(x, contentType='CSV', pk_chunking=True)
    batch = bulk.query(job, "select Id from %s" % x)
    print(bulk.get_batch_list(job))
    print('batch status: ' , bulk.is_batch_done)
    while not bulk.is_batch_done(batch):
        time.sleep(6)
    for result in bulk.get_all_results_for_query_batch(batch):
        result = unicodecsv.DictReader(result, encoding='utf-8')
    # print(result)
    bulk.close_job(job)

Please recommend how can I fix this error and read the large tables from salesforce with batches in parallel?

razdi
  • 1,388
  • 15
  • 21
Kumar
  • 13
  • 3
  • Do you see a concrete error associated with the failed job in Salesforce Setup? What does its request look like? Is the Python library you are using here `salesforce_bulk`? – David Reed Jun 07 '19 at 12:25
  • @DavidReed Yes, I'm using the python library "salesforce_bulk". Here is the error message that I have got using the API: Traceback (most recent call last): File "/sfdc_test.py", line 51, in while not bulk.is_batch_done(batch): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/salesforce_bulk/salesforce_bulk.py", line 428, in is_batch_done raise BulkBatchFailed(job_id, batch_id, status.get('stateMessage'), batch_state) salesforce_bulk.salesforce_bulk.BulkBatchFailed: Batch 7511M00000KiuKjQAJ of job None failed: None – Kumar Jun 07 '19 at 16:33
  • @DavidReed Details from the job monitoring in Salesforce: Concurrency_mode - Parallel,Api Version - 40.0, Records processed - 10000. Batches: Batch id: 7511M00000KiuKjQAJ—> records processed: 0 —> Status: Not Processed —> Request : “select Id from Account" batch Id: 7511M00000kiuko.. —> records processed: 10000—> Status: Completed —> Request : “select Id from Account where Id >= ‘ ’ and Id < ‘ ’ ” – Kumar Jun 07 '19 at 16:34
  • @Kumar Did you find any solution to this issue? I am also facing the same issue while doing pk_chunking – Abid Jul 12 '19 at 07:22

1 Answers1

0

I was facing same error and how i resolved is by adding "job" parameter to get_all_results_for_query_batch(batch,Job)

so code will be like this

table_names = ['Account','table1']
bulk = connect_sfdc_bulk('prod')
for x in table_names:
    job = bulk.create_query_job(x, contentType='CSV', pk_chunking=True)
    batch = bulk.query(job, "select Id from %s" % x)
    print(bulk.get_batch_list(job))
    print('batch status: ' , bulk.is_batch_done)
    while not bulk.is_batch_done(batch):
        time.sleep(6)
    for result in bulk.get_all_results_for_query_batch(batch,job):
        result = unicodecsv.DictReader(result, encoding='utf-8')
    # print(result)
    bulk.close_job(job)
purva
  • 1
  • 1