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
Gonzalo Quevedo 15Gonzalo Quevedo 15 

DynamicPickList Class getDefaultValue() method not working

Hi!, 

I'm populating a configuration picklist using DynamicPickList class in lightning component app builder page, but it seems that getDefaultValue() method is not working. I even copied/pasted Salesforce example and it didn`t work either! :(

This is salesforce example: (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_VisualEditor_DynamicPickList.htm#apex_class_VisualEditor_DynamicPickList)
global class MyCustomPickList extends VisualEditor.DynamicPickList{
    
    global override VisualEditor.DataRow getDefaultValue(){
        VisualEditor.DataRow defaultValue = new VisualEditor.DataRow('red', 'RED');
        return defaultValue;
    }
    global override VisualEditor.DynamicPickListRows getValues() {
        VisualEditor.DataRow value1 = new VisualEditor.DataRow('red', 'RED');
        VisualEditor.DataRow value2 = new VisualEditor.DataRow('yellow', 'YELLOW');
        VisualEditor.DynamicPickListRows  myValues = new VisualEditor.DynamicPickListRows();
        myValues.addRow(value1);
        myValues.addRow(value2);
        return myValues;
    }
}

And this is the picklist output in lightning app builder:
User-added image

User-added image

Anyone is having the same issue? Is something that I missed here?

Thanks!









 
Alain CabonAlain Cabon
Hello,

User-added image
The best article about the dynamic picklist (complete use, better than the Salesforce documentation):

https://agarciaodeian.com/2017/08/08/picklist-dinamicos-en-lightning-components/

The VisualEditor.DataRow seems just useful for selecting the default values.
Joe Markey 6Joe Markey 6
Gonzalo Quevedo 15,

I'm glad you reported this issue as we are experiencing the exact same behavior you are. Within the Lightning App Builder, after initially dragging-and-dropping our Lightning component onto the page, the initial default value of our drop down is an empty value:

Empty Default Value

Here is my code:

Lightning design file:
<design:component label="Conga Composer">
    <design:attribute name="selectedCollectionId" label="Solution Collection" description="This will determine which solutions are displayed" datasource="apex://SolutionCollectionDesigner" required="false" />
</design:component>

Apex class:
public with sharing class SolutionCollectionDesigner extends VisualEditor.DynamicPickList {
    
    public override VisualEditor.DataRow getDefaultValue() {
        System.debug('TEST getDefaultValue()'); //TODO
        VisualEditor.DataRow defaultValue;
        ESAPI.accessController().setSharingMode(SFDCAccessController.SharingMode.WITH);
        if(ESAPI.accessController().isAuthorizedToView(Conga_Collection__c.sObjectType, new List<String>{'Id', 'Name'})) {
            for (Conga_Collection__c c : [SELECT Id, Name FROM Conga_Collection__c ORDER BY Name ASC LIMIT 1]) {
                defaultValue = new VisualEditor.DataRow(c.Name, String.valueOf(c.Id), true);
            }
        }

        return defaultValue;
    }
    
    public override VisualEditor.DynamicPickListRows getValues() {
        System.debug('TEST getValues()'); //TODO
        VisualEditor.DynamicPickListRows  myValues = new VisualEditor.DynamicPickListRows();
        Integer index = 0;
        Boolean selected = false;
        ESAPI.accessController().setSharingMode(SFDCAccessController.SharingMode.WITH);
        if(ESAPI.accessController().isAuthorizedToView(Conga_Collection__c.sObjectType, new List<String>{'Id', 'Name'})) {
            for (Conga_Collection__c c : [SELECT Id, Name FROM Conga_Collection__c ORDER BY Name ASC]) {
                selected = (index++ == 0) ? true : false;
                VisualEditor.DataRow tempVal = new VisualEditor.DataRow(c.Name, String.valueOf(c.Id), selected);
                myValues.addRow(tempVal);
            }
        }

        return myValues;
    }

}

Suspected Salesforfce Bug:
The Salesforce provided Apex method fails to invoke (my system.debug() statement fails to execute):
public override VisualEditor.DataRow getDefaultValue() {
        System.debug('TEST getDefaultValue()'); //TODO
        VisualEditor.DataRow defaultValue;
        ESAPI.accessController().setSharingMode(SFDCAccessController.SharingMode.WITH);
        if(ESAPI.accessController().isAuthorizedToView(Conga_Collection__c.sObjectType, new List<String>{'Id', 'Name'})) {
            for (Conga_Collection__c c : [SELECT Id, Name FROM Conga_Collection__c ORDER BY Name ASC LIMIT 1]) {
                defaultValue = new VisualEditor.DataRow(c.Name, String.valueOf(c.Id), true);
            }
        }

        return defaultValue;
    }


Please post back if you discover a solution!