You need to sign in to do that
Don't have an account?

Create Dynamic Picklists for Lightning App Builder Components
Hello,
We can add a datasource onto the attribute in the design resource, like this:
<design:attribute name="Name" datasource="value1,value2,value3" />
How can I use a dynamic datasource instead of hardcoding the values.
Thanks,
Devendra
Thanks,
Rodney
APEX Controller
Component Controller
Hope someone can help.
We are talking about the attribute in the design resource: <design:attribute name="Name" datasource="{!v.ObjectProperty}" />
my component:
<aura:handler name="init" action="{!c.myAction}" value="{!this}" />
<aura:attribute name="Network" type="String[]"/>
<ui:inputSelect label="Network" class="slds-input"
labelClass="slds-form-element__label" >
<aura:iteration items="{!v.Network}" var="s">
<ui:inputSelectOption text="{!s}"/>
</aura:iteration>
</ui:inputSelect>
my controller:
myAction : function(component, event) {
var action = component.get("c.getPickListValues");
action.setParams({ obj:"Deal_Request__c",str:"Network_Platform__c"});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var stringItems = response.getReturnValue();
component.set("v.Network", stringItems);
}
});
$A.enqueueAction(action);
}
my class:
public class objlist_1_cmp_ctrl {
@AuraEnabled
public static List<String> getPickListValues(String obj, String str) {
String[] options = new String[]{};
//Schema.DescribeFieldResult ccity = Schema.getGlobalDescribe().get(str1).getDescribe().fields.getMap().get(str).getDescribe();
//Schema.DescribeFieldResult ccity = Schema.sObjectType.contact.fields.status__c.getSObjectField().getDescribe();
Schema.DescribeFieldResult plistvalues = Schema.getGlobalDescribe().get(obj).getDescribe().fields.getMap().get(str).getDescribe();
options.add('--None--');
for(PicklistEntry ent:plistvalues.getpicklistvalues())
{
options.add(ent.getLabel());
}
return options;
}
}
Thanks,
Senthil Kumar
I creaded a dynamic picklist in design resources and it works for me. This is my code:
- design file:
<design:component>
<design:attribute name="sObjectName" label="Object Name" datasource="apex://DesignResourcePickList" description="" />
</design:component>
- apex class:
global class DesignResourcePickList extends VisualEditor.DynamicPickList {
global override VisualEditor.DataRow getDefaultValue(){
VisualEditor.DataRow defaultValue = new VisualEditor.DataRow('Tree', 'Tree__c');
return defaultValue;
}
global override VisualEditor.DynamicPickListRows getValues() {
List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
VisualEditor.DynamicPickListRows myValues = new VisualEditor.DynamicPickListRows();
for(Schema.SObjectType objectInstance : gd){
myValues.addRow(new VisualEditor.DataRow(objectInstance.getDescribe().getLabel(), objectInstance.getDescribe().getName()));
}
return myValues;
}
}
The documentation I used is: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_config_for_app_builder_dynamic_picklists.htm
for dynamic datasource instead of hardcoding the values please refer this url.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_config_for_app_builder_dynamic_picklists.htm
Thanks,
Avish
Hi,
We can use datasource in design attribute for dynamic values
component.design :
apex class:
You can use context variable to fetch data related to object
Reference resource:
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_config_for_app_builder_design_files.htm
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_VisualEditor_DesignTimePageContext.htm#apex_VisualEditor_DesignTimePageContext_entityName