I just wanted to check is it possible to save empty value or null value to a decimal field using apex.

Let us take that there is a number field by name Count__c, which needs to be set as blank when certain conditions met. I can do it by workflow field update for new records, but i want to update the existing records. So just thought of writing a script in console, but when i assign a blank value to that field and try to execute it gives me exception that we cannot assign a blank value.

If i can do it via workflow field update why cannot we do it using apex.

1 Answer 1


I'm guessing you probably did something like this:

record.Count__c = '';

This is not a blank value, it's an empty String. To make a field blank, set it to "null":

record.Count__c = null;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.