I have a visualforce page to generate a OpportunityLineItem. It is launched from the Opportunity page. I want a picklist for users to enter a custom field Product_Type__c.
The Opportunity is the controller of record on the page.
I have been able to query the schema for the values. How do I assign this to field?
Here is my Controller snippet:
public class AddProduct {
private ApexPages.StandardController sc;
public Opportunity record {get; private set;}
public OpportunityLineItem ELI {get; set;}
public OpportunityLineItem CusLi {get;set;}
public Opportunity Op {get; set;}
public List<SelectOption> getProdSubTypes1(){
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult = OpportunityLineItem.Product_SubType__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for( Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}
public AddProduct(ApexPages.StandardController controller) {
if (!Test.isRunningTest()) Controller.addFields(new List<String>{'Name', 'PriceBook2Id'});
record = (Opportunity)controller.getRecord();
sc= controller;
ELI = new OpportunityLineItem();
CusLI = new OpportunityLineItem();
}
public PageReference AddEmailProduct (){
Opportunity TheOpp = (Opportunity)sc.GetRecord();
ELI.OpportunityId=TheOpp.id;
ELI.PricebookEntryId=[select id from PricebookEntry where name =: 'Email'
and Pricebook2id=:Theopp.Pricebook2Id].id;
ELI.Quantity=1;
ELI.Product_Type__c='Email';
ELI.Product_SubType__c = ????
insert ELI;
}
VF Page Snip:
<apex:commandButton action="{!AddEmailProduct}" value="Email" />
<apex:selectList size="1">
<apex:selectOptions value="{!ProdSubTypes1}"></apex:selectOptions>
</apex:selectList>