You need to sign in to do that
Don't have an account?
Rost
How to access dependent picklist mapping from Apex?
I have a long list of "Product Types" picklist with controller "Segment" picklist.
I can load complete Product Types picklist in Apex, but how can I get valid list of Product Types for the given Segment?
I searched documentation and only found that there is a field "validFor" that exists for PicklistEntry in API but does not exist in Apex.
My questions are:
1. Is there any "pure-Apex" solution to access the mapping?
2. If not, is there a workaround like calling API from Apex to achieve same goal?
Please find the response to your questions below:-
1. Is there any "pure-Apex" solution to access the mapping?
No through Apex we cannot find the controlling field of a dependant picklist value or vice - versa.
2. If not, is there a workaround like calling API from Apex to achieve same goal?
The solution will be to have a custom object for storing the relationship between the "Controlling Picklist Value" and the "dependant picklist values", but that's bit cumbersome as every time the user makes any change or adds or deletes any picklist item the respective entiries in the custom object has to be modified and one cannot put a trigger of schema modification ( Adding 0o modifying or deleting picklist values is schema modification)
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
i have created custom object :featurecategory__c
field Feature__c:controling feild
Category__c dependent on the feature
ProblemSpace:Category__c picklist is not showing data according to controling.
plz specyfy
controller:
public with sharing class DependentObjects
{
String category;
String feature;
public String getCategory() { return this.category; }
public void setCategory(String s) { this.category = s; }
public String getFeature() { return this.feature; }
public void setFeature(String s) { this.feature = s; }
public List<SelectOption> getFeatures()
{
List<SelectOption> optionList = new List<SelectOption>();
optionList.add(new SelectOption('', '- None -'));
Schema.DescribeFieldResult resultfield=FeatureCategory__c.Feature__c.getDescribe();
List<Schema.PicklistEntry> Ple=resultfield.getPicklistValues();
for (Schema.PicklistEntry f:ple)
{
optionList.add(new SelectOption(f.getLabel(),f.getValue()));
}
return optionList;
}
public void getValues()
{
getCategories();
}
public List<SelectOption> getCategories()
{
List<SelectOption> optionList = new List<SelectOption>();
/* Add a null option to force the user to make a selection. */
optionList.add(new SelectOption('', '- None -'));
/* If a category has been selected then query for the related values */
if(Feature != NULL)
{
/* Loop over the related feature records for the given category
creating a selectOption with the value being the feature record ID
and the label is the name of the feature. */
/* Schema.DescribeFieldResult resultfieldt=FeatureCategory__c.Category__c.getDescribe();
List<Schema.PicklistEntry> Ple=resultfieldt.getPicklistValue(); */
for (FeatureCategory__c ct : [select id from FeatureCategory__c where Category__c = :Feature])
{
optionList.add(new SelectOption(ct.id,ct.name));
}
/* for(Schema.PicklistEntry p:ple)
{optionList.add(new SelectOption(p.getLabel(),P.getValue()));
}*/
}
return optionList;
}
}
visualforce:<apex:page controller="DependentObjects" id="UseCaseDisplay" label="FeatureCategoryReport" sidebar="false">
<apex:form >
<apex:pageBlock title="Feature Selection" mode="edit" id="thePageBlock">
<apex:pageBlockSection columns="1">
<apex:pageblockSectionItem >
<apex:outputLabel value="Feature:" for="Feature"/>
<apex:selectList value="{!Feature}" size="1" id="Feature">
<apex:actionSupport event="onchange" rerender="cate" action="{!getvalues}"/>
<apex:selectOptions value="{!Features}"/>
</apex:selectList>
</apex:pageblockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputPanel id="cate">
<apex:outputLabel value="Category:" for="category"/>
<apex:selectList value="{!Category}" size="1" id="category" >
<apex:selectOptions value="{!Categories}"/>
</apex:selectList>
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Dependent picklist works automatically in VF from the API version 19.0
don't need to do any coding to display dependent picklist in VF.
Thanks, will check with API 19.0.
Rost.