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
Sharad Sharma 38Sharad Sharma 38 

Apex:SelectOption does not show selected value on page reload

I am trying to get values for apex select list from a API call. I can get all the values, show them on the page, do what I need to do etc. However, when I reload (Press F5 or leave the page and come back at later) the page, I my dropdown list does not retain the selected value.

My Controller
public class DocusignTemplates {
	private Signature__c signatures;
    private String selectedTemplate;
    public DocusignTemplates (ApexPages.StandardController controller) {
        signatures = (Signature__c)controller.getRecord();
    }

    public List <SelectOption> filteredTemplates {
        get{
            if(filteredTemplates == null) {
                DocusignRESTUtility dru = new DocuSignRESTUtility();
                String templatesJSON = dru.getDocusignData(DocuSignRESTUtility.TEMPLATES);
                DocusignTemplateListBean templateData = (DocusignTemplateListBean) System.JSON.deserialize(templatesJSON, DocusignTemplateListBean.class);
                List <EnvelopeTemplateBean> envelopeTemplates = templateData.envelopeTemplates;
                
                filteredTemplates = new List<SelectOption>();
                filteredTemplates.add(new SelectOption('','--No Template--'));
                for(EnvelopeTemplateBean envelopeTemplate : envelopeTemplates) {
                    if(envelopeTemplate.name != '')
                        filteredTemplates.add(new SelectOption(envelopeTemplate.templateId, envelopeTemplate.name));
        		}
            }
        	return filteredTemplates;
    	} private set;
    }
    
    public String getSelectedTemplate() {
        return this.selectedTemplate;
    }
    public void setSelectedTemplate(String templateId) {
        this.selectedTemplate = templateId;
    }
    
    public PageReference updateSelectedTemplate() {
        system.debug('selected template: '+ getSelectedTemplate());
        this.signatures.Selected_Template__c = getSelectedTemplate();
        update this.signatures;
        return null;
    }
}

My Visualforce page
<apex:page standardController="Signature__c" extensions="DocusignTemplates" lightningStylesheets="true">
    <apex:form style="margin-left:-0.9em">
        <apex:outputLabel >Select Template</apex:outputLabel><br/>
        <apex:selectList size="1" style="margin-left:0px;width:100%" value="{!selectedTemplate}" id="TemplateNameList">
            <apex:actionSupport event="onchange" action="{!updateSelectedTemplate}"/>
            <apex:selectOptions value="{!filteredTemplates}"/>
        </apex:selectList><p/>
    </apex:form>
</apex:page>
Before reloading page, everything works fine and I can store value in another field
image1After reloading page, selected value is not retained
image2

How do I retain the value in Dropdown after page reload?