function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jprosserjprosser 

Casting LIST:SOBJECT:Product2 to LIST:System.SelectOption

Hey Folks,
I'm building my own add a product to an opportunity field using visualforce. I'm working on the select products page and I'm trying to do this with a selectCheckboxes widget.  Is this the correct approach?  Should I be using a wizard approach to support the multi-line page that follows?

I need to provide a selectOption list out of a product2 query. Does anyone know how to do this?

Code:
 public List<SelectOption> getItems() {
List<SelectOption> products = new List<SelectOption>();

products= [select Id, Name from product2 ];
return products;
}


 
-Joe
hisrinuhisrinu
Hi Joe,


public List<SelectOption> getItems() {
List<SelectOption> products = new List<SelectOption>();
for (product2 p : [select name from product2])
products.add(new SelectOption(p.name,p.name));
return products;
}
Thanks
Srini
jprosserjprosser
Thanks Srini!

Do you know if there is a way to easily display the selectOptions with columns?

It looks like all you can do is create each SelectOption and pad with whitespace.

Cheers,
-Joe
hisrinuhisrinu
Hi Joe,

I dont have any idea on that.
Just you can add some space and then you can show it as a single record.



Thanks
Srini