pythonsalesforcesfdc

Python Salesforce Toolkit - Blank/Reset SFDC field via API


I am using the python salesforce toolkit for SFDC integration with a home grown application. We have nightly routines to read and write to SFDC. Based on a condition, I need to set the date value to current date or reset it to blank. I can set the date value, no issues. But I am unable to set the value to blank.

data = {}
if condition==True:
    data['Termination_Date__c'] = '2017-05-12'
else:
    data['Termination_Date__c'] = ??

I've tried to use '', 'null' and None while trying to blank out the value but nothing works so far. I am sure it's an easy solution but just can't find a way out. Any help would be appreciated.


Solution

  • I found a solution to the question I posted. It's true that you can set '' to string fields to update them in SFDC. But certain fields like Date won't accept an empty string because of the validation rules in SFDC. A python None doesn't work either. But the toolkit has a way to handle such situation. Here's how you can blank/null the field in SFDC:

    data = {}
    if condition==True:
        data['Termination_Date__c'] = '2017-05-12'
    else:
        data['fieldsToNull'] = ['Termination_Date__c']