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
Connor ReillyConnor Reilly 

Update visualforce picklist field based on values from a string field

Hi all, 
I'm looking to update a picklist on a visualforce page, based on the values from a text formula field. 

Visualforce Page: 
 

<apex:page standardController="Scorecard__c" extensions="ScorecardExtension" lightningStylesheets="true">
    <apex:form >
        <apex:pageBlock title="Scorecard" mode="edit">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Calculate"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection columns="2">
                <apex:outputField value="{!Scorecard__c.Name}"/>
                <apex:outputText value=""/>
                <apex:outputField value="{!Scorecard__c.Revenue_M__c}"/>
                <apex:outputText value=""/>
                <apex:inputField value="{!Scorecard__c.Revenue__c}"/>
                <li Style="list-style:none">{!Scorecard__c.Calculate_Revenue__c}/150</li>
                <apex:outputField value="{!Scorecard__c.Full_NAICS_Codes__c}"/>
                <apex:outputText value=""/>
                <apex:inputField value="{!Scorecard__c.Industry__c}"/>
                <li Style="list-style:none">{!Scorecard__c.Calc_Industry__c}/100</li>
                <apex:inputField value="{!Scorecard__c.Sourcing_Frequency__c}"/>
                <li Style="list-style:none">{!Scorecard__c.Calc_Sourcing_Frequency__c}/100</li>
                <apex:inputField value="{!Scorecard__c.Role__c}"/>
                <li Style="list-style:none">{!Scorecard__c.Calc_Job_Function_Pick__c}/100</li>
                <apex:inputField value="{!Scorecard__c.Sourcing_Type__c}"/>
                <li Style="list-style:none">{!Scorecard__c.Calc_Sourcing_Type__c}/100</li>
                <apex:inputField value="{!Scorecard__c.Opportunity_Size__c}"/>
                <li Style="list-style:none">{!Scorecard__c.Cal_Opportunity_Size__c}/100</li>
                <apex:inputField value="{!Scorecard__c.Target_Pricing__c}"/>
                <li Style="list-style:none">{!Scorecard__c.Calc_Target_Pricing__c}/40</li>
                <apex:inputField value="{!Scorecard__c.Manufacturing_Processes__c}"/>
                <li Style="list-style:none">{!Scorecard__c.Calc_Manufacturing_Process__c}/50</li>
                <apex:inputField value="{!Scorecard__c.Customer_Responsiveness__c}"/>
                <li Style="list-style:none">{!Scorecard__c.Calc_Customer_Responsiveness__c}/85</li>
               <li Style="list-style:none"><apex:outputField value="{!Scorecard__c.Score__c}"/>{!Scorecard__c.Score__c}/825</li>
             </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

If Revenue_M__c is populated, I want to update the Revenue__c field accordingly. I've started a controller extension, but don't know if that's the right way to go. 

public class ScorecardExtension {
 
    private final Scorecard__c sccard;
    
    public ScorecardExtension(ApexPages.StandardController stdController) {
        this.sccard = (Scorecard__c)stdController.getRecord();
    }
    
    public String getRevenue() {
         switch on this.sccard.Revenue_M__c {
            when '<10' {	
                this.sccard.Revenue__c = '<$5m (or no size on Zoominfo)';
            }	
            when '11-25' {		
                this.sccard.Revenue__c = '$5-250m';
            }
            when '26-50' {	
                this.sccard.Revenue__c = '$5-250m';
            }
            when '51-250' {	
                this.sccard.Revenue__c = '$5-250m';
            } 
            when '251-500' {	
                this.sccard.Revenue__c = '$250m+';
            } 
            when '501-2,500' {	
                this.sccard.Revenue__c = '$250m+';
            } 
            when '2,501-5,000' {	
                this.sccard.Revenue__c = '$250m+';
            }
            when '5,000+' {	
                this.sccard.Revenue__c = '$250m+';
            } 
            when else {		
                this.sccard.Revenue__c = 'None';
            }
        }
    
        return this.sccard.Revenue__c;
    }
}

Any help or guidance would be appreciated. 

Thanks,
Connor
AnudeepAnudeep (Salesforce Developers) 
Hi Connor - As per my understanding you want to conditionally render fields on Visualforce page based on picklist values

I recommend taking a look at the following sample code
 
<apex:pageBlock id="xxxpb1">

<apex:pageBlockSection>
                    
<apex:actionRegion >               

  <apex:inputField id="xxxif1" value="{!Object.picklistfieldapiname1}" required="true" >

     <apex:actionSupport event="onchange" rerender="xxxpb1" />
  </apex:inputField>

</apex:actionRegion>
                 
</apex:pageBlockSection>
               
<apex:pageBlockSection id="xxxpbs1" rendered="true">

 <apex:inputField id="xxxif2" value="{!Object.Fieldtobedisplayed1}" rendered="{!IF(Object.picklistfieldapiname1 ='picklist value 1' || lead.Buyer_Type__c ='picklist value 2' ,true,false)}"/>

</apex:pageBlockSection>

<apex:pageBlockSection id="xxxpbs2" rendered="true">

  <apex:inputField id="xxxif3" value="{!Object.Fieldtobedisplayed2}" rendered="{!IF(Object.picklistfieldapiname1 ='picklist value 3' || lead.Buyer_Type__c ='picklist value 4' ,true,false)}"/>  
                                                                     
</apex:pageBlockSection>

</apex:PageBlock>

See this documentation to learn more

Let me know if this helps, if it does, please close the query by marking it as solved. It may help others in the community. Thank You!