This is my VF page which has one Picklist Field and it is dynamic, I mean when a record is created in another object for ex:two__c, it's record name will get added to this picklist values.
Now the problem is when i map field from VF page to custom fields in order to save record in database, it is saving all fields except that Picklist value, here is my VF page and Custom Controller.
VF Page
<apex:page sidebar="false" standardController="check__c" extensions="accPickNamesDisplayClass1" tabStyle="check__c">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!record_insert}" />
</apex:pageBlockButtons>
<apex:pageBlockSection title="Information" >
<apex:pageBlockSectionItem >
<apex:outputLabel >Project</apex:outputLabel>
<apex:selectList multiselect="false" size="1">
<apex:selectOptions value="{!accNames}" />
</apex:selectList>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Name</apex:outputLabel>
<apex:inputText value="{!Name}" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Email</apex:outputLabel>
<apex:inputText value="{!Email}" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Phone</apex:outputLabel>
<apex:inputText value="{!Phone}" />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
This is my controller
public class accPickNamesDisplayClass1 {
public String Phone { get; set; }
public String Email { get; set; }
public String Name { get; set; }
public String accNames { get; set; }
public accPickNamesDisplayClass1(ApexPages.StandardController controller) {}
public accPickNamesDisplayClass1() {}
public PageReference record_insert () {
check__c check = new check__c (
Name__c = Name
,Email__c Email
,Mobile__c = Phone
,Project_Stage__c = accNames
);
insert check;
check.clear();
PageReference page = new PageReference('https://ap1.salesforce.com/a1t/o');
page.setredirect(false);
return page;
}
List<selectOption> options = new List<selectOption>();
public List<selectOption> getAccNames() {
for(two__c acc : [select Id,name from two__c])
{
options.add(new selectOption(acc.name,acc.name));
}
return options;
}
}