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

How to set default value for a managed field in salesforce?

I have a managed field from a package. The requirement is such that I can not add this field to page layout. But when I create or clone a record some managed code throws the error that the particular field is required. Since it is not included in page layout, users can not set any value.

Is there any way I can set a default value for this field?

Thanks in advance.


You can use trigger and set default value or you can set a default value directly in the field using formula field


I have already tried using before trigger but it throws error even before the triggers are fired.

About formula field, please explain how can I set value for this field from a different formula field. The field in question is a currency field.


Use default value/formula field under the object  to set to some value so that it won't be null.

I just tested this and its working fine for me. 


Just a note:

I think the best way to implement this process is by using record types and Page layouts.

That way you restrict the access to based on fields from different profiles. Even if the field is required, if it is not present on the page layout, user will not be forced. Thats the same way it should work for Managed fields in packages, I am suprised that its throwing a error.


It's throwing error because managed code is doing null validation on the field.

Also, i am not able to understand your solution based on formula field. Formula fields can assign value to themselves and not to other fields if I am not wrong.

The field in question comes from a managed package and I can neither change the data type nor set a default value on the field like other custom fields.

Any thoughts?


If you have field and field validation in managed code then there is no way you can change it. It is a limitation in salesforce.

You can support the the existing idea that is put on Salesforce.