0

I have one custom Picklist field in which based upon logged-in user's Profile default value should be selected. For example: Test_Picklist__c

Values: 'Sys Admin', 'Client', 'Other' Default Value formula:

IF($Profile.Name = 'System Administrator', 'Sys Admin', 
IF($Profile.Name = 'Client', 'Client', 'Other'))

From salesforce standard page, default value is set which means above formula is working fine.

But I want to get above computed result in my custom Visualforce page.

On searching over internet I found solutions which returns value level default selection.

List <Schema.PicklistEntry> pickVals = F.getPicklistValues();
for (Schema.PicklistEntry av: pickVals) {
    if (av.isDefaultValue()) {
        defaultVal = av.getValue();
    }
}

Is their any way to get Default Value which is calculated via formula.

0

There's now a method to recalculate formula values in visualforce:

someSObject.recalculateFormulas();

Documentation here: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject.htm

There are some limitation, though I can't remember what they are. To tell the truth, I'd probably just put the formula logic into the controller. That would give you 100% visibility for debugging and whatnot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.