You need to sign in to do that
Don't have an account?
Knet15
How can I fill a picklist with existence objects?
Hello,
I am new guy programing with apex, I was looking for a way to fill a picklist with objects data. For example:
I have a class called product with price and name, so we will suppose I added some products like juice, milk, etc.
Then I want to create a page with a picklist and fill it with the data I got (product class).
Is this possible? how can I?
Could any body provide me some information?
Thank you very much,
Greetings.
I am new guy programing with apex, I was looking for a way to fill a picklist with objects data. For example:
I have a class called product with price and name, so we will suppose I added some products like juice, milk, etc.
Then I want to create a page with a picklist and fill it with the data I got (product class).
Is this possible? how can I?
Could any body provide me some information?
Thank you very much,
Greetings.
if product is a custom object, use product__c, otherwise if it's standard product object, then don't use __c
Public List<product__c> listProducts {get;set;}
listProducts = new List<product__c>([Select name from product__c]);
public List<SelectOption> listOfProductsForPage {get; private set;}
for(product__c product : listProducts) {
listOfProductsForPage.add(new selectoption(product.name,product.name));
}
On page :-
<apex:selectlist multiselect="false" size="1" >
<apex:selectoptions value="{!listOfProductsForPage}" >
</apex:selectoptions>
</apex:selectlist>
public string productlist{get;set;}
public product(ApexPages.StandardController controller) {
}
public list<selectoption> getproducts()
{
list<selectoption> l1=new list<selectoption>();
l1.add(new selectoption('','-none-'));
l1.add(new selectoption('1','juice'));
l1.add(new selectoption('2','milk'));
return l1;
}
}
<apex:page standardController="account" showHeader="false" extensions="product">
<apex:form >
<apex:pageBlock >
<apex:inputField value="{!account.name}"/>
<apex:selectList value="{!productlist}" label="products" size="1">
<apex:selectOptions value="{!products}">
</apex:selectOptions>
</apex:selectList>
</apex:pageBlock>
</apex:form>
</apex:page>