function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Lori VardiLori Vardi 

Clear sObject field value

Hi,
Im using salesforce java  api-core 1.0.3 and im trying to clear a field using the sObject apis.
I tried to use setField with null or empty string or to use removeField with no success.
What is the way to clear a custom field value using java APIS?
 
Best Answer chosen by Lori Vardi
Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi  Lori Vardi,

Add you field to fieldsToNull Array of one or more field names whose value you want to explicitly set to null.

https://www.salesforce.com/developer/docs/api/Content/sforce_api_calls_concepts_core_data_objects.htm#i1421117

Let us know if it helps.

All Answers

Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi  Lori Vardi,

Add you field to fieldsToNull Array of one or more field names whose value you want to explicitly set to null.

https://www.salesforce.com/developer/docs/api/Content/sforce_api_calls_concepts_core_data_objects.htm#i1421117

Let us know if it helps.
This was selected as the best answer
Lori VardiLori Vardi
Thank u!
unfotunatliy im using com.palominolabs.crm.sf.rest that doesn't have these setters and getters.
Can you think of a way to do it otherwise?
Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Could you please explain us your whole scenario ?
Lori VardiLori Vardi
Offcourse,
Im using a third party connector https://github.com/palominolabs/sf-api-connector to update salesforce objects from our backend system, via rest apis.
As i already mentioned im trying to clear fields value unfortunatly in that implementation there is no setFieldsToNull method:
 https://github.com/palominolabs/sf-api-connector/blob/master/api-core/src/main/java/com/palominolabs/crm/sf/core/SObject.java

Can you think of a way to do it without changing my sf connector?

 
Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi Lori,

Please try below code to insert a new object .
SObject newLead = RestSObjectImpl.getNew("Lead");
newLead.setField("LastName", "Smith");
newLead.setField("Company", "null");
 
SaveResult result = connection.create(newLead);

Let us know if it helps.
Lori VardiLori Vardi
Almost,
Accutally putting field with null value works now, I thought it didn't work but it was because of a diffrent reason.
SObject newLead = RestSObjectImpl.getNew("Lead");
newLead.setField("LastName", "Smith");
newLead.setField("Company", null);
 
SaveResult result = connection.create(newLead);
The third party put it as fieldsToNull when null is defined.
Thank u for your help,