Nulling fields in Salesforce with SoapUI

The Problem

The other day I came across a problem where sending in a blank field to Salesforce via SOAP was not nulling out the field.  Instead, the enterprise WSDL was treating this as if nothing was sent, and therefore not updating the field at all.  This make sense.  If you were to send a sparse data structure over with only fields you want to update, you wouldn’t want to either have to provide the current value of every field or have them all nulled out.  So, how do you null out a field with SOAP via the enterprise (or partner) WSDL in Salesforce?

The Solution

NOTE: This is input is formatted for SoapUI, it may differ depending on the client you are using to send the SOAP message.  The key take away is fieldToNull urn.

Lets start with a simple example of updating a field via the Enterprise WSDL

This will set the CustomField__c on the Contact to “Yay! Data”

 

To null out this field we simply send the field name as part of the fieldsToNull list

 

This entry was posted in developement, salesforce and tagged , , , , , . Bookmark the permalink.
  • crop1645

    Patrick — thank you very much; This and your other posts on testing via SOAP the SFDC API as well as custom Apex webservices saved me much time

  • Kiran Joshi

    Hello Patrick, Its a great work to have documented like this. Thanks for your patience, it saves a lot of time for lot of people.

    However I have a query,

    ABC
    ABC: data value too large: SwarrantyStandard warranty (max length=12)
    STRING_TOO_LONG

    false

    ABC
    ABC: data value too large: SwarrantyStandard warranty (max length=12)
    STRING_TOO_LONG

    false

    This is the response I get when I use an enterprise wsdl. Now why is this “id” coming as null? It should ideally return what is the request which you have sent right? correct me if I am wrong. As I am consuming webservices and I am triggering this “update” service in bulk by seeing the response how should I identify which error is for what?

    Thanks for your blog again :)

  • http://about.me/patrick.connelly Patrick Connelly

    Kiran, I’d need more information. Can you please provide me with the full SOAP request that you made (with your sessionId redacted). You can use gist or pastebin to make formatting easier.

    If this is a custom webservice, it would be nice if you could also include code for that.

  • Kiran Joshi

    Thanks Patrick :)

    Below is the request and response from SOAP UI (Screenshots attached to this post),

    To be clear the service is triggered from the enterprise wsdl not a custom web service.

    I have attached request and response for only one item, Now consider this situation if id is not returned in case of multiple? How should I validate which response message is for which item.

    I hope you got my question.
    And Thanks again :)