1

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 sam@sample.com:

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

UpdateSingleSalesforceObject('Contact',@personid,'Email','sam@sample.com')
]%%

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?

3

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','delete@email.co')
]%%
  • 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. – Eliot Harper Dec 21 '16 at 21:10
  • And this workaround works perfectly, BTW! – Eliot Harper Dec 22 '16 at 6:11
8

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

UpdateSingleSalesforceObject('Contact', @personid, 'fieldsToNull', 'Email')
  • You have your parameters backwards, it should be field to update then value to update. Also, using 'fieldsToNull' just sets the value to 'fieldsToNull'. – victorcorey Apr 4 '18 at 17:38
  • @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 Apr 5 '18 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.