After record creation, if the record is edited I want to auto-populate picklist value which is dynamic and I have a value which am passing it in apex:repeat

<select Class="slds-input form-control">
    <apex:repeat value="{!updateObj.MFF_RelatedFldval}" var="pickOpts"  >
        <option value="{!pickOpts.value}" >{!pickOpts.label}</option> //Account,contact,case

I want the {!updatePicklstFldValsMap[updateObj.MFF_FieldName]} //contact value to be selected in the picklist.

Specified the below statement after apex:repaeat which added two same values in the picklist (Contact)

<option selected="selected">{!updatePicklstFldValsMap[updateObj.MFF_FieldName]}</option>


In that case, you can use <apex:ouputPanel> and rendered it without the value you want to display as selected (i.e picklist values not equal to select value in rendered condition) and outside the <apex:repeat> specify the value in the selected tag but make sure the empty value is not passed and it is made as selected

    <select Class="slds-input form-control" >
      <option value="">--None--</option>

         <apex:outputPanel rendered="{!len(updatePicklstFldValsMap[updateObj.MFF_FieldName]) >0 }">
            <option selected="selected">{!updatePicklstFldValsMap[updateObj.MFF_FieldName]}</option>

         <apex:repeat value="{!updateObj.MFF_RelatedFldval}" var="pickOpts"  >
           <apex:outputPanel rendered="{!pickOpts.value != updatePicklstFldValsMap[updateObj.MFF_FieldName]}">
             <option value="{!pickOpts.value}">{!pickOpts.label}</option>

I believe there is no way you can do it via standard repeat:

As you commented and it is also documented:

HTML5 specifications


The selected content attribute is a boolean attribute.

http://www.w3.org/TR/html5/infrastructure.html#boolean-attributes :

The presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value.

If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing white-space.

If any of the option elements contain selectedword, it will be selected regardless of value corresponding to selected attribute.

The one option I see is to use <apex:selectList and <apex:selectOptions> tag instead of apex repeat and set the default value in controller binding field.


<apex:selectList size="1" value="{!bindingField}">
     <apex:selectOptions value="{!options}"/>



else, you can always use JavaScript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.