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
Christopher Peck 16Christopher Peck 16 

Passing URL parameter to managed picklist

I'm new to visualforce but trying to edit a page built by another. I need to set a picklist value, that can be changed on the form, to a value defined in the URL.

The URL that is pass includes:

?channel=email&market=1&lang=en

I'm trying to set the market picklist here:

<div class="new-subform-component form-group field">
     <label for="select_market" class="control-label id="select_market">{!$Label.Select_Market}:</label>
     <div>
          <apex:inputField value="{!caseObj.Case_Market__c}"
               Styleclass="form-control caseMarket" required="true" id="market" onchange="UpdateCountryCode()" />
     </div>
</div>

This is pulling the options from the Case.Case_Market__c field. Each Market(Country) as an API value that is a number but of course the number is considered text type.

If I add an onload function:

window.onload=function() {
                $('.caseMarket').val('1');
        };

This works, 1 = USA

Anything refencing the URL parameter, doesn't work such as:

var xMarket = '{($CurrentPage.parameters.market == null, '1', $CurrentPage.parameters.market)}';

window.onload=function() {
            if (xMarket == "1"){
                $('.caseMarket').val('1');
            } else if (xMarket == "2") {
                $('.caseMarket').val('2');
            }
            UpdateCountryCode()
        };

Or setting the .caseMarket by parameter on load:

window.onload=function() {
     $('.caseMarket').val('$CurrentPage.parameters.market');
}

I have tried many, many different ways of doing this, all failing. Ideas?
osacar sotoosacar soto
Marcel Meijer 2Marcel Meijer 2
If you set the value in the APEX constructor of the page, this will work.
So something like:
public with sharing class myClass {

	private ApexPages.StandardController stdCtrl{get;set;}
	Case c;
	
	public myClass(ApexPages.StandardController std) {
		Case c = new Case();
		c = (Case) stdCtrl.getRecord(); 
		c.Case_Market__c = ApexPages.currentPage().getParameters().get('market'); 
	}

}