SOQL: Convert set to list
I am trying to get unique items from an object so I am starting with a set however I need the values to be returned as a list for the visualforce
and populating a list with unique values from a SOQL query?
public List getItems() { Set license = new Set( [SELECT Name FROM License__c] ); List options = new List(); options.addAll(license); return options; }
To convert set to list, their is no need to work with lists and sets if you group-by in the query:
public List getItems() { List options = new List(); for(AggregateResult l : [SELECT Name FROM License__c GROUP BY Name]){ options.add(new SelectOption(String.valueOf(l.get('Name')),String.valueOf(l.get('Name')))); } return options; }