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
hkp716hkp716 

Populate Product name in select list

How can I populate my select list with the product names?  I know instead of creating new options:

 List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('US','US'));
options.add(new SelectOption('CANADA','Canada'));
options.add(new SelectOption('MEXICO','Mexico'));
return options;

 

I have to call the name field in the products object but i can't fiqure out how to do it.  Anyone got any ideas?

-Hkp716

 

 

public with sharing class plist1 {
String[] prods = new String[]{};

public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('US','US'));
options.add(new SelectOption('CANADA','Canada'));
options.add(new SelectOption('MEXICO','Mexico'));
return options;
}

public String[] getprods() {
return prods;
}

public void setprods(String[] prods) {
this.prods = prods;
}


public List<Product2> getProducts() {

List<Product2> ProductsForPage = [Select Id,Name,Brand__c From Product2];
return ProductsForPage;


}
}

Best Answer chosen by Admin (Salesforce Developers) 
JHayes SDJHayes SD

Try this:

 

public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        List<Product2> ProductsForPage = [Select Id,Name,Brand__c From Product2];
        for (Product2 p : ProductsForPage) {
        	options.add(new SelectOption(p.Name, p.Name));
        }        
        return options;
    }

 Regards, jh

All Answers

JHayes SDJHayes SD

Try this:

 

public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        List<Product2> ProductsForPage = [Select Id,Name,Brand__c From Product2];
        for (Product2 p : ProductsForPage) {
        	options.add(new SelectOption(p.Name, p.Name));
        }        
        return options;
    }

 Regards, jh

This was selected as the best answer
hkp716hkp716

Worked perfectly you're an SFDC god.  Now i just need to create a button to transfer selected name to another list.

 

-hkp716