Understanding the Difference Between Default Expression and Create Trigger
There are two ways you can assign default values to fields in a newly-created row and it is important to understand the difference between them.
The first way is to provide a default value expression for one or more fields in
your object. Your default value expression should not depend on other fields in
the same object since you cannot be certain of the order in which the fields are
assigned their default values. The default value expression should evaluate to a legal
value for the field in question and it should not contain any field assignments or any
setAttribute()
calls as part of the expression. The framework
evaluates your default expression and assigns it to the field to which it is associated
automatically at row creation time.
On the other hand, If you need to assign default values to one or more fields after first
allowing the framework to assign each field's literal default values or default value
expression, then the second way is more appropriate. Define a Create
trigger on the object and inside that trigger you can reference any field in the object
as well as perform any field assignments or setAttribute()
calls to
assign default values to one or more fields.