You need to sign in to do that
Don't have an account?
Michael J. Lupino
Deduplicate list of records for insert into SelectList (dropdown)
Hi,
I have some functionality that reads a group of records from a related list for display in a pageblock table based on a criteria i have set in the SOQL query. I have some values in a field lets call the field filterA that could be duplicate of other items. I'd like to read the full list of records for my query and dedup any entries.
I've tried set but as the record ids are unique, I'll end up with the same number of records being read. Any ideas on how I can screen out the duplicates?
Here's a visual example:
Filter A (values)
A
A
A
A
A
A
B
B
C
My end result would be to get a list with A,B,C vs. displaying all values as I plan to pass A,B,C, to a selectlist and selectoption. I'm interested in this because This field Filter A would then be used in another piece of functionality to effectively filter based on a action from a command button and a SOQL query that would engage Filter A. I prefer to build this list based on the data vs. hardcoding.
I have some functionality that reads a group of records from a related list for display in a pageblock table based on a criteria i have set in the SOQL query. I have some values in a field lets call the field filterA that could be duplicate of other items. I'd like to read the full list of records for my query and dedup any entries.
I've tried set but as the record ids are unique, I'll end up with the same number of records being read. Any ideas on how I can screen out the duplicates?
Here's a visual example:
Filter A (values)
A
A
A
A
A
A
B
B
C
My end result would be to get a list with A,B,C vs. displaying all values as I plan to pass A,B,C, to a selectlist and selectoption. I'm interested in this because This field Filter A would then be used in another piece of functionality to effectively filter based on a action from a command button and a SOQL query that would engage Filter A. I prefer to build this list based on the data vs. hardcoding.
Seems like your field FilterA is a non groupable field. Some fields like picklist, multipicklists are non groupable.
If the list you want to create is list of strings then you can try Set<String>.
What is the datatype of the field Filter? Is it lookup to some other object?
Thanks
Anupama
All Answers
Try to use the aggregate query to group the records by the filterA.
Thanks
Anupama
Can you post your SOQL query here. I can look at it.
Thanks
Anupama
Seems like your field FilterA is a non groupable field. Some fields like picklist, multipicklists are non groupable.
If the list you want to create is list of strings then you can try Set<String>.
What is the datatype of the field Filter? Is it lookup to some other object?
Thanks
Anupama
In that case you can use the code snippet in my previous comment to create the list of select option and show it as picklist on page. As formula fields are non groupable.
Thanks
Anupama
for(objectname__c r : [Select id, valuetoadd From objectname where fieldname_c ='filter goes here']){
NameofSet .add(r.valuetoadd__c);
}//END for
for (String a : NameofSet) {
nameoflist.add(new SelectOption(a, a));
}
return nameoflist;
} //returns back to dropdown list on vf page