1

I have 3 selectList on a VF page. In the controller I have the personID which is the id of the record that I want to put the values of what a user selects in these 3 fields.

1) give each of the 3 fields a handle. When I tried using ID I got an error. 2) What code would I put in my save method in order save it? Update on Program__c Set field1=tosomething, field2=tosomething, fields3=tosomething where id = :personID or something like that?

 <apex:PageBlock title="Choose Your Preferred Seminar(s) for {!progName}">

            <apex:pageBlockButtons >
                <apex:commandButton action="{!saveItem}" value="Save"/>
                <apex:commandButton action="{!cancelAction}" value="Cancel"/>
            </apex:pageBlockButtons>

            <h1>First Preference:</h1><p />
                   <apex:selectList value="{!names}" multiselect="false" size="1">
                   <apex:selectOptions value="{!items}"/>
                   </apex:selectList>
            <p />
                    <h1>Second Preference:</h1><p />
                   <apex:selectList  value="{!names}" multiselect="false" size="1">
                   <apex:selectOptions value="{!items}"/>
                   </apex:selectList>
             <p />
                    <h1>Third Preference:</h1><p />
                   <apex:selectList value="{!names}" multiselect="false" size="1">
                   <apex:selectOptions value="{!items}"/>
                   </apex:selectList>
</apex:PageBlock>

      </apex:form>

1

Instead of three names to hold values, i would point them to the exact fields to be assigned.

<apex:selectList value="{!person.preference1__c}" multiselect="false" size="1">
<apex:selectList value="{!person.preference2__c}" multiselect="false" size="1">
<apex:selectList value="{!person.preference3__c}" multiselect="false" size="1">

Here preference1__c, preference2__c & preference3__c are the fields to be updated in the Person object which id you have. It would automatically assign the values selected to the fields.

Then in your controller you can update it like

update person;

Note;

person should be declared as public with getters and setters which should of same type as personId. The personId should be assigned to this as person = new Person__c(id = personId);

Hope it helps.

| improve this answer | |

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.