You need to sign in to do that
Don't have an account?
How to display other child related field values in lookups via picklist
Hello
I am displaying a lookup (Name) value in my pikclist value, which is a lookup to another object. I was hoping to display a different field value (not the autonumber .Name value) in the picklist value. Or perhaps a string of multiple values (Name.customfield__c). Is this possible?
This code gives the name (autonumber) value, but i would like to display the (miiFinance__Display_Name__c) value, and capture the Id so it saves correctly. Here is my code so far.
VF
<apex:page StandardController="Invoice__c" extensions="MultiAdd,CurrencyPL,TaxPL,ProductPL" id="thePage"> <apex:form > <apex:pageblock id="pb" > <apex:pageBlockButtons > <apex:commandbutton value="Add Line Item" action="{!Add}" rerender="pb1"/> <apex:commandbutton value="Save Invoice" action="{!Save}"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Information" columns="2" collapsible="false"> <apex:inputField value="{!Invoice__c.Customer__c}" required="true" /> <apex:selectList required="true" id="icurr" value="{!Invoice__c.Currency__c}" size="1"> <apex:selectOptions value="{!getCurrency}"/> </apex:selectList> <apex:inputField value="{!Invoice__c.Date_Document__c}" required="true" /> <apex:inputField value="{!Invoice__c.Type__c}" required="true" /> <apex:inputField value="{!Invoice__c.Due_Date__c}" required="true" /> </apex:pageBlockSection> <apex:pageblock id="pb1"> <apex:repeat value="{!lstInner}" var="e1" id="therepeat"> <apex:panelGrid columns="8"> <apex:panelGrid headerClass="Name"> <apex:facet name="header">Delete</apex:facet> <apex:commandButton value="Remove" action="{!Del}" rerender="pb1"> <apex:param name="rowToBeDeleted" value="{!e1.recCount}" assignTo="{!selectedRowIndex}"></apex:param> </apex:commandButton> </apex:panelGrid> <apex:panelGrid title="SPD" > <apex:facet name="header">Display Name</apex:facet> <apex:inputfield value="{!e1.acct.Display_Name__c}" required="true"/> </apex:panelGrid> <apex:panelGrid > <apex:facet name="header">Product</apex:facet> <apex:selectList id="prod" value="{!e1.acct.Product_For_Sale__c}" size="1" title="Product"> <apex:selectOptions value="{!getProduct}"/> </apex:selectList> </apex:panelGrid> <apex:panelGrid > <apex:facet name="header">Tax</apex:facet> <apex:selectList id="tax" value="{!e1.acct.Tax__c}" size="1" title="Tax"> <apex:selectOptions value="{!getTax}"/> </apex:selectList> </apex:panelGrid> <apex:panelGrid > <apex:facet name="header">Currency</apex:facet> <apex:selectList id="curr" value="{!e1.acct.Currency__c}" size="1" title="Currency"> <apex:selectOptions value="{!getCurrency}"/> </apex:selectList> </apex:panelGrid> <apex:panelGrid > <apex:facet name="header">Invoice</apex:facet> <apex:inputfield value="{!e1.acct.Invoice__c}" required="true" /> </apex:panelGrid> <apex:panelGrid > <apex:facet name="header">Amount inc Tax</apex:facet> <apex:inputfield value="{!e1.acct.Amount_Inc_Tax__c}" required="true" /> </apex:panelGrid> </apex:panelgrid> </apex:repeat> </apex:pageBlock> </apex:pageblock> </apex:form> </apex:page>
Here is the class which is involved. If i get this one, i can replicate the code and make it all work
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 from miiFinance__Product_For_Sale__c]) product.add(new selectOption(pr.id, pr.Name)); return product; } Set; } }
I believe the line
[select Name from miiFinance__Product_For_Sale__c])
is the issue, and when i add the custom field, i get the error
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: miiFinance__Product_For_Sale__c.Name
I add that field to my query
product.add(new selectOption(pr.id, pr.Name, pr.miiFinance__Display_Name__c));
i get this error
Error: ProductPL Compile Error: Constructor not defined: [System.SelectOption].<Constructor>(Id, String, String) at line 10 column 17
Line 10 is the code above
Please let me know your thoughts
Dave
Select options consist of a value and a label. The first parameter to the constructor is the value, and you definitely want to leave that as is. The second parameter is the label, and that can consist of any string that you wish. If you want to display additional information, simply concatenate the values, e.g.
All Answers
Select options consist of a value and a label. The first parameter to the constructor is the value, and you definitely want to leave that as is. The second parameter is the label, and that can consist of any string that you wish. If you want to display additional information, simply concatenate the values, e.g.
Thank you, i got it working.
For further information, here was my final class