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
Christopher PezzaChristopher Pezza 

Remove Duplicates from a List for a dropdown

SET<Customer_Health__c> CSMList = [SELECT Customer_Success_Manager__c FROM Customer_Health__c];
    List<Customer_Health__c> CSMList2 = new CSMList2();
    CSMList2.addAll(CSMList);

get and error for unexpected token where bolded and underlined

Any ideas to fix?

Trying to create a dropdown of athe CSMs where there is only one of each, it is a text field.
Best Answer chosen by Christopher Pezza
Avidev9Avidev9
You need to do it bit differently, you can't just add the data returned from query.
You need to add the text field explicitly into the set

Set<String> cmSet = new Set<String>();
for(Customer_Health__c ch : [SELECT Customer_Success_Manager__c FROM Customer_Health__c]){
      cmSet.add(ch.Customer_Success_Manager__c);
}



All Answers

Jim JamJim Jam
Your declaration of CSMList2 should be ..

List<Customer_Health__c> CSMList2 = new List<Customer_Health__c>();
Shri RajShri Raj
List<Customer_Health__c> CSMList2 = new CSMList2();
SET<Customer_Health__c> CSMList = new SET<Customer_Health__c>() ;
CSMList = [SELECT Customer_Success_Manager__c FROM Customer_Health__c];
    
    CSMList2.addAll(CSMList);

Give a try with this!
Christopher PezzaChristopher Pezza
Frank I still get the error of Unexpected token of ')' at the very end of CSMList2.addAll(CSMList);

Shri It doesnt like the CSMList = Query, it doesnt know how to handle the = sign
Avidev9Avidev9
You need to do it bit differently, you can't just add the data returned from query.
You need to add the text field explicitly into the set

Set<String> cmSet = new Set<String>();
for(Customer_Health__c ch : [SELECT Customer_Success_Manager__c FROM Customer_Health__c]){
      cmSet.add(ch.Customer_Success_Manager__c);
}



This was selected as the best answer
Christopher PezzaChristopher Pezza
Avidev9
It didnt work said expecting right curly bracket, found 'for';
Avidev9Avidev9
Can you post your full code ? So that I can see what you are doing ?
Christopher PezzaChristopher Pezza
Ok Avidev9 THe code did work, I forgot to put the for loop in the constructor. now my question is how to put it in a list that i output in the <apex:SelectOptions> tag