bulk insert Time Field via Simple-Salesforce

1.2k Views Asked by At

I am trying to create a record in Salesforce using the simple-salesforce bulk insert. The record in question has Salesforce's new "Time" fields, which are causing the import to fail. My question is how can I format (or otherwise modify) the time values so that the record will be accepted by the simple-salesforce .insert() command.

My code is as follows:

record = [{'Name': 'Event XZY',
  'Event_Date__c': '2018-09-28',
  'Start_Time__c': '16:00:00.000Z',
  'End_Time__c': '18:00:00.000Z'}]

sf.bulk.Custom_Event_Object__c.insert(record)

The error I receive is the standard and not relevant Response content: {'exceptionCode': 'InvalidBatch', 'exceptionMessage': 'Records not processed'}.

The format of the time fields has not been changed from when the data was imported from another object. When I remove the 'Time' fields the record is created successfully. I have also tried formatting the time fields as 'T16:00:00.000Z','16:00:00Z', '16:00:00z', and '4 pm' as well, but none have worked. The insert also works fine when exported to a csv and uploaded with the Data Loader application.

2

There are 2 best solutions below

3
On

I think your format is wrong for seconds: https://developer.salesforce.com/docs/atlas.en-us.dataLoader.meta/dataLoader/data_loader_dates.htm?search_text=date

"Only dates within a certain range are valid. The earliest valid date is 1700-01-01T00:00:00Z GMT, or just after midnight on January 1, 1700. The latest valid date is 4000-12-31T00:00:00Z GMT, or just after midnight on December 31, 4000. These values are offset by your time zone. For example, in the Pacific time zone, the earliest valid date is 1699-12-31T16:00:00, or 4:00 PM on December 31, 1699."

In your examples you're including an extra 0 before the Z timezone character, try doing:

'Start_Time__c': '16:00:00.00Z',
0
On

You can format time in 'hh:mm:ss' format. so you can try '04:00:00' for 4 am and 16:00:00 for 4 pm.