fieldsToNull in Salesforce API Call

Array of one or more field names whose value you want to explicitly set to null.
When used with update() or upsert(), you can specify only those fields that you can update and that have the nillable property. When used with create(), you can specify only those fields that you can create and that have the nillable or the default on create property.

For example, if specifying an ID field or required field results in a runtime error, you can specify that field name in fieldsToNull. Similarly, if a picklist field has a default value and you want to set the value to null instead, specify the field in fieldsToNull.

To reset a field value to null, you add the field name to the fieldsToNull array in the sObject. You cannot set required fields (nillable is false) to null.

Sample Code:

  1. sObject objContact = new sObject();  
  2. objContact.type = "Contact";  
  3. // Set the value of LastName to null  
  4. errorContact.fieldsToNull = new String[] { "LastName" };  

No comments:

Post a Comment