[SalesForce] Default value for date field

I have created a new date field and set the default value to 'today()'. The date value is being shown for all the new records that are created after the creation of this date field. But the old records do not hold a value for this date field. Is there a way that I can update the date value for all the old records?

Best Answer

You can use Developer Console's Execute Anonymous feature to accomplish that.
You will find it on Debug drop down list on Developer Console.

Query null values from desired object and update them.

Code Example for Account object:

List<Account> AccList = [select id,customDateField__c from Account where customDateField__c = null];
for(Account a:AccList){
   a.customDateField__c = system.today();
}

update AccList;
Related Topic