You need to sign in to do that
Don't have an account?
DRobi83
Lookup as Picklist - Set a NULL value by default and display lookup values as selectlist options
Hello
I have a class which is looking up object records to display in a picklist. My issue is that by default, the picklist field is displaying a value. I would like to default value to be NULL (user has to select one), and then the values under NULL (- None -) be the records of my class query
Thanks in advance
VF
<apex:page standardController="Invoice__c" extensions="newInvoiceLineItems,CurrencyPL,TaxPL,ProductPL"> <apex:form > <apex:sectionHeader title="Invoice and Credit Memo" subtitle="{!Invoice__c.Name}" /> <apex:pageBlock title="Invoice and Credit Memo Detail" > <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}" rerender="error" /> <apex:commandButton value="Cancel" action="{!cancel}" rerender="error" /> </apex:pageBlockButtons> <apex:pageMessages ></apex:pageMessages> <apex:pageBlockSection title="Information" columns="2" collapsible="false"> <apex:inputField value="{!Invoice__c.Customer__c}" required="true" /> <apex:pageBlockSectionItem > <apex:outputLabel value="Currency"/> <apex:outputPanel layout="block" styleClass="requiredInput" > <apex:outputPanel layout="block" styleClass="requiredBlock"/> <apex:selectList value="{!Invoice__c.Currency__c}" required="True" size="1" id="invoicecurr"> <apex:selectOptions value="{!getCurrency}"/> </apex:selectList> </apex:outputPanel> </apex:pageBlockSectionItem> <apex:inputField value="{!Invoice__c.Date_Document__c}" required="true" /> <apex:inputField value="{!Invoice__c.Due_Date__c}" required="true" /> <apex:inputField value="{!Invoice__c.Type__c}" required="true" /> <apex:pageBlockSectionItem > <apex:outputLabel value="Description"/> <apex:outputPanel layout="block" styleClass="requiredInput" > <apex:outputPanel layout="block" styleClass="requiredBlock"/> <apex:inputTextarea value="{!Invoice__c.Description__c}" required="true" cols="40" rows="3" /> </apex:outputPanel> </apex:pageBlockSectionItem> </apex:pageBlockSection> <apex:pageBlockTable value="{!lines}" var="li" id="table"> <apex:column headerValue="Line Items" colspan="2"> <apex:outputLabel value="Description"/> <apex:inputField value="{!li.Display_Name__c}" required="true"/> <apex:outputLabel value="Amount inc Tax"/> <apex:inputField value="{!li.Amount_Inc_Tax__c}" required="true"/> <apex:outputLabel value="Invoice"/> <apex:inputField value="{!li.Invoice__c}"/> <apex:outputLabel value="Currency"/> <apex:outputPanel layout="block" styleClass="requiredInput" > <apex:outputPanel layout="block" styleClass="requiredBlock"/> <apex:selectList value="{!li.Currency__c}" required="True" size="1"> <apex:selectOptions value="{!getCurrency}"/> </apex:selectList> </apex:outputPanel> <apex:outputLabel value="Product"/> <apex:outputPanel layout="block" styleClass="requiredInput" > <apex:outputPanel layout="block" styleClass="requiredBlock"/> <apex:selectList value="{!li.Product_For_Sale__c}" required="True" size="1"> <apex:selectOptions value="{!getProduct}"/> </apex:selectList> </apex:outputPanel> <apex:outputLabel value="Tax"/> <apex:outputPanel layout="block" styleClass="requiredInput" > <apex:outputPanel layout="block" styleClass="requiredBlock"/> <apex:selectList value="{!li.Tax__c}" required="True" size="1"> <apex:selectOptions value="{!getTax}"/> </apex:selectList> </apex:outputPanel> <apex:outputLabel value="Quantity"/> <apex:inputField value="{!li.Quantity__c}" required="true"/> <apex:commandLink value="Add Row" action="{!addRow}" rerender="table,error" immediate="true" /> | <apex:commandLink value="Remove Row" action="{!removeRow}" rerender="table,error" immediate="true" /> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
class
public class ProductPL { private miiFinance__Invoice__c invoice; public ProductPL(ApexPages.StandardController controller) { this.invoice = (miiFinance__Invoice__c)controller.getRecord(); } public List <SelectOption> getProduct { Get{ List <SelectOption> product = new List <SelectOption>(); for( miiFinance__Product_For_Sale__c pr: [select Name, miiFinance__Display_Name__c from miiFinance__Product_For_Sale__c]) product.add(new selectOption(pr.id, pr.Name + ' - ' + pr.miiFinance__Display_Name__c)); return product; } Set; } }
Hi,
Try the below code snippet as reference:
========VF============================
<apex:page controller="picklistDemo" >
<apex:form >
User Picklist
<apex:selectList id="sl_ur" value="{!AddUser}" size="1" multiselect="false" style="width:152px;" >
<apex:selectOptions value="{!SelectUser}"/>
</apex:selectList>
</apex:form>
</apex:page>
==========Apex Controller==========================
public class picklistDemo {
public List<SelectOption> SelectUser{get;set;}
public String AddUser { get; set; }
public picklistDemo()
{
List<User> us=[select id,Name from User];
system.debug('_________us_size'+us.size());
SelectUser=new List<SelectOption>();
SelectUser.add(new SelectOption('--None--','-None-'));
for(User ur:us)
{
SelectUser.add(new SelectOption(ur.id,ur.Name));
system.debug('________name'+ur.Name+'________id'+ur.id);
}
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Thanks Navatar
That code is only displaying the -None- values, and not my values
Here is some modified code, but perhaps you could look and see if it can be modified to display null/-None- first off, and also my lookup values?