Find your content:

Search form

You are here

How to set default value for a managed field?

 
Share

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.


Attribution to: Anutosh Datta

Possible Suggestion/Solution #1

You could try using a Before Insert Apex Trigger to set the value for you?

trigger CaseBefore on Case (before insert) {
        if(Trigger.new != null){
            for(Case cs : Trigger.new){

                if(cs.YourField__c == null){
                    cs.YourField__c = 'Your Value';
                }
            }
        }
}

Attribution to: Jon Hazan

Possible Suggestion/Solution #2

The authors of the managed packaged must be validating the field in a trigger -- which sounds like a good idea, until you run into a customer who doesn't have a use for the field, or for some reason, can populate the field in the same way every time.

If the managed package is a required component, I don't know of any solution for this problem, unless the author of the managed package publishes an update that lets you indicate a default as a custom setting (or something).

Or, removes the validation altogether. If it's a situation where it would might be reasonable for someone to use a default, then it's questionable as to whether the field really needs to be required (or whether the package author needs to check for null or empty fields).

-Ted.


Attribution to: Ted Husted
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/1443

My Block Status

My Block Content