2

I need to update the Email field in the Salesforce Contact Object to null.

If I use the following code, the email field in the Contact Object is updated to [email protected]:

%%[
var @personid 
set @personid = Lookup('Ent.All Services','PersonID','Id', _subscriberkey)

UpdateSingleSalesforceObject('Contact',@personid,'Email','[email protected]')
]%%

However, I can't figure out how to update this to a null value. I have tried:

UpdateSingleSalesforceObject('Contact',@personid,'Email',null)

And:

UpdateSingleSalesforceObject('Contact',@personid,'Email','')

But this does not update the email address.

I understand that the UpdateSingleSalesforceObject() function is a wrapper for the Salesforce API and according to this documentation you need to include a fieldsToNull array, but this is not an option in the AMPscript function.

Does anyone know a solution to this?

2 Answers 2

2

I understand your dilemma. I have a solution, albeit a total hack.

  1. Create a workflow in Salesforce ORG to set email to null when a specific value is assigned.

  2. Modify AMPScript code to assign a dummy value in scenarios where email should be null.


Screenshot of custom workflow in Sales Cloud:


enter image description here


AMPscript example:

%%[  
 UpdateSingleSalesforceObject('Contact',@personid,'Email','[email protected]')
]%%
2
  • Thanks David, I was thinking of exactly the same solution. It looks like this is the only feasible workaround. I could create a Connected App and make a Salesforce REST API request in AMPscript, but that's not a good idea for a few different reasons. Dec 21, 2016 at 21:10
  • And this workaround works perfectly, BTW! Dec 22, 2016 at 6:11
18

The function does allow fieldsToNull, although not very well documented. The following code should work.

UpdateSingleSalesforceObject('Contact', @personid, 'fieldsToNull', 'Email')
4
  • You have your parameters backwards, it should be field to update then value to update. Also, using 'fieldsToNull' just sets the value to 'fieldsToNull'. Apr 4, 2018 at 17:38
  • 1
    @victorcorey not in the case of using the 'fieldsToNull' parameter. You are correct when that parameter is not being used. When the parameter is used, the logic is backward. The value truly gets set to an empty value.
    – Steve J
    Apr 5, 2018 at 18:55
  • 2
    Confirmed that this works. If you have multiple fields to update, you need to make several calls, but it works. This should be the selected answer. Dec 17, 2019 at 2:18
  • 2
    Also confirmed that this works on a multi-select picklist. Jan 24, 2020 at 1:14

You must log in to answer this question.

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