We have a Salesforce custom webservice; this custom webservice is consumed by an external application.

This custom webervice supports an upsert on Contact object and the source application is trying to make the middle name blank in Salesforce using custom upsert.

Below is a sample code which we are using in our custom webservice class:

Contact cnt=new Contact();
        cnt.lastname ='LNAME';
        cnt.setFieldsToNull(new String[]{'MiddleName'});

Error: Compile Error: Method does not exist or incorrect signature: void setFieldsToNull(List) from the type Contact

Can anyone please let us know, how do we make Salesforce to update null values through custom webservice.

  • 2
    This is Apex Code?
    – sfdcfox
    Apr 26, 2018 at 18:44

1 Answer 1


SetFieldsToNull is not a provided Salesforce method for any object, including Contact. You have to write it yourself. Thankfully, it should be a real simple function to write using apex:

public static sObject SetFieldsToNull(sObject record, List<String> fields) {
    for (String field:fields) {
        record.put(field, null);

    return record; 

// Call like this: 

Contact someContact = new Contact();

someContact = (Contact)SetFieldsToNull(someContact, new List<String>{ 'MiddleName' });

You must log in to answer this question.

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