+ Start a Discussion
Developer 8876Developer 8876 

custom select list won't save

Hi, so I've been trying to save values from a custom select list called campusIdOptions for a custom objects edit page, the values have been displaying but not saving, I would greatly appriacate any input on this problem, I have attached the code below, thank you for your time 

<apex:page standardController="Facilities__c"   extensions="FacilitiesEditPageControllerExtension">
<apex:sectionHeader title="Edit Facility" subtitle="{!Facilities__c.Name}"/>
<apex:form >
    <apex:pageBlock title="Edit Facility" mode="edit"  >
        <apex:pageBlockSection title="Information" columns="2">
            <apex:pageBlockSection columns="1" />

                <!--apex:inputField value="{!Facilities__c.campus__c}"/-->
                <apex:selectList value="{!Facilities__c.campus__c}" size="1" >
                    <apex:selectOptions value="{!campusIdOptions}" />

           <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="Save"/>
            <apex:commandButton action="{!doSaveAndNew}" value="Save & New"/>
            <apex:commandButton action="{!Cancel}" value="Cancel"/>


public class FacilitiesEditPageControllerExtension 
       ApexPages.standardController m_sc = null;
    public static integer counter = 100000;
    Facilities__c fc;
    public SelectOption[] campusIdOptions{
        public get{ return campusIdOptions; }
        private set{ campusIdOptions = value; } 
    public FacilitiesEditPageControllerExtension(ApexPages.StandardController controller)
        fc = (Facilities__c) controller.getrecord();
        m_sc = controller;
    public void getOptionsForCampusIds()
        Id accId = fc.account__c;
        List<facilities__c> facilityList = [SELECT Name, campus__c, Account__r.id FROM facilities__c WHERE Account__r.id =: accId];
        List<Decimal> facility_campus_ids = new List<Decimal>();
        campusIdOptions = new List<SelectOption>();
        if (facilityList != null)
            for (facilities__c s : facilityList)
                if ( s.campus__c != null)
                    Decimal campusNumber = s.campus__c;
                    //campusIdOptions.add(new SelectOption(campusNumber.toPlainString(), campusNumber.toPlainString()) );
    public SelectOption Create_new()
           List<facilities__c> facilityList = [SELECT id, campus__c
                                            FROM facilities__c 
                                            Where campus__c != null
                                               Order By campus__c Desc
                                            Limit 1
        return new SelectOption((facilityList[0].campus__c + 2).format(),'Create New');
  public Pagereference doSaveAndNew()
    SObject so = m_sc.getRecord();
    upsert so;
    string s = '/' + ('' + 'setup/ui/recordtypeselect.jsp?ent=01I44000000EElz&retURL=%2Fa0w%2Fo&save_new_url=%2Fa0w%2Fe%3FretURL%3D%252Fa0w%252Fo') + '/e?';
    ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.Info, s));
    return new Pagereference(s);


Amol Salve 14Amol Salve 14

Your code is working fine you just need to change two line,
Facilities__c so = m_sc.getRecord();
upsert so;

SObject so = m_sc.getRecord();
upsert so;

Thank you
Amol Salve
Salesforce Developer