Skip to main content
improved formatting
Source Link
Mark Pond
  • 23.1k
  • 2
  • 60
  • 104

<apex:page standardController="Opportunity" extensions="">

<apex:page standardController="Opportunity" extensions="">
    
    <apex:form id="form" >
        
        <apex:outputLabel >Channel Group:</apex:outputLabel>
        <apex:selectList id="countries" value="{!Opportunity.Channel_Group__c}" size="1">
            <apex:actionSupport event="onchange" action="{!setValue}" rerender="form"/>
            <apex:selectOptions value="{!ChannelGroup}"/> 
        </apex:selectList>
        
        <apex:outputLabel >Channel Group:</apex:outputLabel>
        <apex:selectList id="countriess" value="{!Opportunity.Channel_Type__c}" size="1">
            <apex:selectOptions value="{!ChannelType}"/>
        </apex:selectList>
        
        
    </apex:form>
    
</apex:page>

</apex:page>

Controller:

public class Sample{

public class Sample{
    
    Opportunity opp;
    public List<SelectOption> channelTypeOptions;
    
    public Sample(ApexPages.StandardController controller) {
        opp = (Opportunity) controller.getRecord();
    }
    
    public List<SelectOption> getChannelGroup()
    {
        List<SelectOption> channelGroupOptions = new List<SelectOption>();
        
        Schema.DescribeFieldResult fieldResult = Opportunity.Channel_Group__c.getDescribe();
        List<Schema.PicklistEntry> channelGroupValue = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry cg : channelGroupValue)
        {
            channelGroupOptions.add(new SelectOption(cg.getLabel(), cg.getValue()));
        }       
        return channelGroupOptions;
    }
    
    public List<SelectOption> getChannelType()
    {
        channelTypeOptions = new List<SelectOption>();
        
        Schema.DescribeFieldResult fieldResult = Opportunity.Channel_Type__c.getDescribe();
        List<Schema.PicklistEntry> channelTypeValue = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry ct : channelTypeValue)
        {
            channelTypeOptions.add(new SelectOption(ct.getLabel(), ct.getValue()));
        }       
        return channelTypeOptions;
    }
    public void setValue(){
        if(opp.Channel_Group__c == 'Direct'){
            channelTypeOptions.add(new SelectOption('Outside Sales','Outside Sales'));
        }
    }
}

}

<apex:page standardController="Opportunity" extensions="">

<apex:form id="form" >
    
    <apex:outputLabel >Channel Group:</apex:outputLabel>
    <apex:selectList id="countries" value="{!Opportunity.Channel_Group__c}" size="1">
        <apex:actionSupport event="onchange" action="{!setValue}" rerender="form"/>
        <apex:selectOptions value="{!ChannelGroup}"/> 
    </apex:selectList>
    
    <apex:outputLabel >Channel Group:</apex:outputLabel>
    <apex:selectList id="countriess" value="{!Opportunity.Channel_Type__c}" size="1">
        <apex:selectOptions value="{!ChannelType}"/>
    </apex:selectList>
    
    
</apex:form>

</apex:page>

Controller:

public class Sample{

Opportunity opp;
public List<SelectOption> channelTypeOptions;

public Sample(ApexPages.StandardController controller) {
    opp = (Opportunity) controller.getRecord();
}

public List<SelectOption> getChannelGroup()
{
    List<SelectOption> channelGroupOptions = new List<SelectOption>();
    
    Schema.DescribeFieldResult fieldResult = Opportunity.Channel_Group__c.getDescribe();
    List<Schema.PicklistEntry> channelGroupValue = fieldResult.getPicklistValues();
    for( Schema.PicklistEntry cg : channelGroupValue)
    {
        channelGroupOptions.add(new SelectOption(cg.getLabel(), cg.getValue()));
    }       
    return channelGroupOptions;
}

public List<SelectOption> getChannelType()
{
    channelTypeOptions = new List<SelectOption>();
    
    Schema.DescribeFieldResult fieldResult = Opportunity.Channel_Type__c.getDescribe();
    List<Schema.PicklistEntry> channelTypeValue = fieldResult.getPicklistValues();
    for( Schema.PicklistEntry ct : channelTypeValue)
    {
        channelTypeOptions.add(new SelectOption(ct.getLabel(), ct.getValue()));
    }       
    return channelTypeOptions;
}
public void setValue(){
    if(opp.Channel_Group__c == 'Direct'){
        channelTypeOptions.add(new SelectOption('Outside Sales','Outside Sales'));
    }
}

}

<apex:page standardController="Opportunity" extensions="">
    
    <apex:form id="form" >
        
        <apex:outputLabel >Channel Group:</apex:outputLabel>
        <apex:selectList id="countries" value="{!Opportunity.Channel_Group__c}" size="1">
            <apex:actionSupport event="onchange" action="{!setValue}" rerender="form"/>
            <apex:selectOptions value="{!ChannelGroup}"/> 
        </apex:selectList>
        
        <apex:outputLabel >Channel Group:</apex:outputLabel>
        <apex:selectList id="countriess" value="{!Opportunity.Channel_Type__c}" size="1">
            <apex:selectOptions value="{!ChannelType}"/>
        </apex:selectList>
        
        
    </apex:form>
    
</apex:page>

Controller:

public class Sample{
    
    Opportunity opp;
    public List<SelectOption> channelTypeOptions;
    
    public Sample(ApexPages.StandardController controller) {
        opp = (Opportunity) controller.getRecord();
    }
    
    public List<SelectOption> getChannelGroup()
    {
        List<SelectOption> channelGroupOptions = new List<SelectOption>();
        
        Schema.DescribeFieldResult fieldResult = Opportunity.Channel_Group__c.getDescribe();
        List<Schema.PicklistEntry> channelGroupValue = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry cg : channelGroupValue)
        {
            channelGroupOptions.add(new SelectOption(cg.getLabel(), cg.getValue()));
        }       
        return channelGroupOptions;
    }
    
    public List<SelectOption> getChannelType()
    {
        channelTypeOptions = new List<SelectOption>();
        
        Schema.DescribeFieldResult fieldResult = Opportunity.Channel_Type__c.getDescribe();
        List<Schema.PicklistEntry> channelTypeValue = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry ct : channelTypeValue)
        {
            channelTypeOptions.add(new SelectOption(ct.getLabel(), ct.getValue()));
        }       
        return channelTypeOptions;
    }
    public void setValue(){
        if(opp.Channel_Group__c == 'Direct'){
            channelTypeOptions.add(new SelectOption('Outside Sales','Outside Sales'));
        }
    }
}
Source Link
Jana Shree
  • 477
  • 2
  • 4
  • 17

Change value on picklist based on another picklist value changes

I want to change picklist value based on another picklist value changes. I have tired below this code. Why this code not working. Anybody please correct my code..

VF:

<apex:page standardController="Opportunity" extensions="">

<apex:form id="form" >
    
    <apex:outputLabel >Channel Group:</apex:outputLabel>
    <apex:selectList id="countries" value="{!Opportunity.Channel_Group__c}" size="1">
        <apex:actionSupport event="onchange" action="{!setValue}" rerender="form"/>
        <apex:selectOptions value="{!ChannelGroup}"/> 
    </apex:selectList>
    
    <apex:outputLabel >Channel Group:</apex:outputLabel>
    <apex:selectList id="countriess" value="{!Opportunity.Channel_Type__c}" size="1">
        <apex:selectOptions value="{!ChannelType}"/>
    </apex:selectList>
    
    
</apex:form>

</apex:page>

Controller:

public class Sample{

Opportunity opp;
public List<SelectOption> channelTypeOptions;

public Sample(ApexPages.StandardController controller) {
    opp = (Opportunity) controller.getRecord();
}

public List<SelectOption> getChannelGroup()
{
    List<SelectOption> channelGroupOptions = new List<SelectOption>();
    
    Schema.DescribeFieldResult fieldResult = Opportunity.Channel_Group__c.getDescribe();
    List<Schema.PicklistEntry> channelGroupValue = fieldResult.getPicklistValues();
    for( Schema.PicklistEntry cg : channelGroupValue)
    {
        channelGroupOptions.add(new SelectOption(cg.getLabel(), cg.getValue()));
    }       
    return channelGroupOptions;
}

public List<SelectOption> getChannelType()
{
    channelTypeOptions = new List<SelectOption>();
    
    Schema.DescribeFieldResult fieldResult = Opportunity.Channel_Type__c.getDescribe();
    List<Schema.PicklistEntry> channelTypeValue = fieldResult.getPicklistValues();
    for( Schema.PicklistEntry ct : channelTypeValue)
    {
        channelTypeOptions.add(new SelectOption(ct.getLabel(), ct.getValue()));
    }       
    return channelTypeOptions;
}
public void setValue(){
    if(opp.Channel_Group__c == 'Direct'){
        channelTypeOptions.add(new SelectOption('Outside Sales','Outside Sales'));
    }
}

}