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
moeoomoeoo 

Update method - to override with empty string

Hi All
 
I've created the custom field with create method. Then I want to update the field value with empty string but it didn't update the value. Following is the example code;
 
//Create customer

Customer__c objCustomer = new Customer__c();

objCustomer.Account__c = "1234"; //String data type

SaveResult[] sr = binding.create(new sObject[] { objCustomer });

 

//Update customer

objCustomer.Account__c = "";

objCustomer.Id = _SalesforceID;

SaveResult[] sr = binding.update(new sObject[] { objCustomer });

I want the Account__c value to be empty string but it is not updated. If I put some value (e.g "1122"), it is updated.

Do I need to set any other value if I want to pass empty string?

Thanks in advance

Moe

SuperfellSuperfell
You need to use the fieldsToNull array instead. e.g.
objCustomer.fieldsToNull = new String [] { "Account__c" };
moeoomoeoo
Thanks for your reply Simon.
 
I didn't realise that empty string has to be handled like this.
 
I've 100 custom fields and the values are coming from database. So, I cannot tell which field will be empty or not. It looks like I have to check if the length is zero, add the field neame to that fieldsToNull string array.
 
Is there any way I can get the current field name easily?
 
Or
 
Is there any other quick fix for this problem?
 
Thanks
 
Moe