+ Start a Discussion
Suresh RaghuramSuresh Raghuram 

Avoid adding duplicate values into picklist

Hi Community,

Below is the sample code
List<User> salesOffice = [Select id, Sales_Office__c, profile.Name from User  where Sales_Office__c != null];

for(User usr: salesOffice){

this.pickList.add(new salesOffice(usr.Sales_Office__c, usr.Sales_Office__c));

From the above process I am getting the duplicate values in the picklist and displaying in the alphabetical order. 

Any Ideas please.


Hi Suresh,

Do u have duplicate values in Sales_Office__C field?
If yes then loop through the salesOffice list and put it into a set<String>.
Suresh RaghuramSuresh Raghuram
Ya I did it with a set but made a mistake by placing it under another for loop now i corrected my mistake thanks for the reply