Another Salesforce blog!!!

Salesforce, Apex

custom field features – default field values

Adding default values to your fields improves the usability of your appliation and can reduce the number of fields needed on the screen.

Default values defined on custom fields apply in the native user interface and VF UI’s


Create a Year text custom field in the object and in the default value provide the formula:

By default, the Apex code does not apply default values when you construct/initialize an SObject via new Season();

But you can request for defaults to be applied utilizing the SObjectType.newSObject method.

Season__c season (Season__c) Season__c.SObjectType.newSObject(null,true);
System.Debug('my default value is: + season.Year__c);


Leave a Reply

Your email address will not be published. Required fields are marked *