0

I have a dataframe of two columns namely Id and datetimehelp (Holds time stamp value).

Given below is the view of the data in the dataframe labelled account_update_subset

Id,datetimehelp
123,18/05/18 9:50
567,18/05/18 9:45

I am writing the below Python code to have this update to a Salesforce object (Account) but it throws me an error Response content: {'exceptionCode': 'InvalidBatch', 'exceptionMessage': 'Records not processed'}

if len(account_update_subset) > 0:
    key_update_attributes_list = []
    update_attributes_list = []
    for i in range(len(account_update_subset)):
        update_attributes_data = {'Id': account_update_subset['Id'].iloc[i],
                              'datetimehelp': account_update_subset['datetimehelp'].iloc[i]}

        update_attributes_list.append(update_attributes_data)
        sf_data_cursor.bulk.Account.update(update_attributes_list)

Could anyone help me find where am I going wrong in this Python script. Thanks

4
  • I'm not sure if it's the specific cause of this error, but your bulk Update call appears to be indented one stop too far. It belongs outside the loop.
    – David Reed
    Commented May 18, 2018 at 12:50
  • @DavidReed, this works just fine if I try to pass a date timestamp in the format dd/mm/yy. This error pops out if the format is dd/mm/yy hh:mm:ss if this might help..
    – dark horse
    Commented May 18, 2018 at 14:38
  • Is the Salesforce field a Date or DateTime field? dd/mm/yy hh:mm:ss is likely not valid. This looks like simple_salesforce; is that right?
    – David Reed
    Commented May 18, 2018 at 15:04
  • Try using yyyy-MM-ddTHH:mm:ss.SSSZ format.
    – Avijit
    Commented May 18, 2018 at 18:36

1 Answer 1

0

I'm assuming here that you're using simple_salesforce, because your bulk invocation looks like that API.

It's not immediately clear to me which of these issues causes the specific error you're observing, but I see at least three issues with this code.

  1. You are repeatedly updating the same Accounts, which results in creation of way more of your limited Bulk API jobs than you probably want to use.

    for i in range(len(account_update_subset)):
        update_attributes_data = {'Id': account_update_subset['Id'].iloc[i],
                          'datetimehelp': account_update_subset['datetimehelp'].iloc[i]}
    
        update_attributes_list.append(update_attributes_data)
        sf_data_cursor.bulk.Account.update(update_attributes_list)
    

Note that here, your update() call is inside the for loop where you accumulate updatable Accounts in update_attributes_list. You should move that update() call outside the loop, so that you call it exactly once for the entire list in a single operation. Right now, the first Account in your list is getting updated len(account_update_subset) times.

  1. You appear to be providing an invalid field for update, 'datetimehelp'. If this is a custom field, you'll need to refer to it by the proper API name, such as'datetimehelp__c'.

  2. The date-time values you're providing in dd/mm/yy hh:mm:ss are not a valid format for Salesforce to accept. The valid incoming formats are documented here and depend on whether your target field is Date or DateTime in type:

YYYY-MM-DD
YYYY-MM-DD hh:mm:ss
YYYY-MM-DD hh:mm:ss
YYYY-MM-DDThh:mm:ssZ
YYYY-MM-DDThh:mm:ss.sssZ

2
  • thanks for your reply. My apologies for keying in few in-correct data. Point 2 and 3 are as per what you mentioned. However I see the error is when the bulk.Account.update happens. And I am trying to figure how to modify the for loop to satisfy that. On another note, if I try to update just the date component (YYYY-MM-DD) to a column of type Date it works just fine. However when I try to update a value (YYYY-MM-DD hh:mm:ss) to a column of type Date/time this error throws up..
    – dark horse
    Commented May 18, 2018 at 17:37
  • @darkhorse You need to un-indent the update call by one tab to remove it from the loop.
    – David Reed
    Commented May 18, 2018 at 18:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .