0

I have a VF select-list component on a Visualforce page. This select-list is populated by a controller method. When adding this method to controller, the submit button (linked to a pageReference !Save in the controller) stops working. The page just seems to refresh when i click it and the record I want to create is not inserted. Below is the VF page component:

<apex:outputLabel style="font-size:11px; font-family:Verdana ">Health Plan</apex:outputLabel><br/> 
<apex:selectList size="1" value="{!cs.Health_Plan__c}" label="" styleClass="myField" >
<apex:selectOptions value="{!SNANAMatch}" />
</apex:selectList><br/><br/>

And below is the method:

           User u = [SELECT Id, ContactId, FirstName FROM User WHERE Id = :UserInfo.getUserId()];

           Contact c = [SELECT Id, LastName, AccountId FROM Contact WHERE Id =:u.ContactId];

           Account a = [SELECT Id, Name FROM Account WHERE Id = :c.AccountId];

           List<Services_NaviNetAccountNumbers_Accounts__c> sn = [SELECT Id, Name, Service_Offering__r.NaviNet_Display_Name__c FROM Services_NaviNetAccountNumbers_Accounts__c WHERE Account__c = :a.Id]; 

           List<Service_Offering__c> serviceList = new List<Service_Offering__c>();

 public Set<SelectOption> getSNANAMatch(){

        Set<SelectOption> DeDupedHPList = new Set<SelectOption>();
               DeDupedHPList.add(New SelectOption('Not Health Plan Related', 'Not Health Plan Related'));  

        List<String> HealthPlanStrings = New List<String>();

        for (Services_NaviNetAccountNumbers_Accounts__c snanas : sn){

        HealthPlanStrings.add(snanas.Service_Offering__r.NaviNet_Display_Name__c);

        }




        HealthPlanStrings.sort();

        for (String plan : HealthPlanStrings){
        deDupedHPList.add(new SelectOption(plan, plan));

        }

            return DeDupedHPList;

    }

This seems to work well with other functions including the apex:SelectOptions value = "{!methodhere} or when using a manually generated list of apex:selectoption 's but for some reason this method appears to be blocking the submission. It does not make much sense since this method is what populates the values for the select-list and is already complete complete by the time one would click "Submit."

Is there anything I am missing here that would have this method keep my PageReference Save() from executing properly?

Thanks,
CP

2
  • 2
    First thing to do is make sure you have an apex:pageMessages tag in your page so you can see messages that may explain the problem.
    – Keith C
    Commented Mar 2, 2016 at 18:15
  • That was a helpful start that threw an error telling me my health_plan__C value is not valid
    – Chris P
    Commented Mar 2, 2016 at 18:21

1 Answer 1

0

Thanks to the helpful comment from @Keith C, I was able to determine that the problem here is this: SelectOptions cannot be populated on visualforce components from a Set. Being un-ordered by nature, there is no guaranteee that the value from the last screen will carry over. I resolved this by channging the return statement at the end of my method:

 List<SelectOption> finalTRXs = new List<SelectOption>();

    for (SelectOption t : TRXTypes ) {
        finalTRXs.add(t);
    }

        return finalTRXs;

By putting the set back into a list, the error was resolved and I was able to submit without issue

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .