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
KeithlarsKeithlars 

Duplicate values being added to SET

I'm merging the values from two multiselect picklist into a SET which I thought was suppose to prevent duplicate values from being added.  See code below.  However, after I run through the SET and update my variable the same value appears twice.  Am I missing something?

// Set up list to hold unique area of interests
Set<String> interests = new Set<String>();
...
                   for (Lead aoiLanding : trigger.new) {
                       interests.add(a.area_of_interest_landing__c);
                       interests.add(a.area_of_interest__c);
                   }
                   // Populate variable to be used in update
                   Integer i = 0;
                   for (String s : interests) {
                       if (i == 0)
                           aoiValue = s;
                       else
                           aoiValue = aoiValue + ';' + s;
                       i++;
                   }
                   a.area_of_interest__c = aoiValue;

SuperfellSuperfell
Are you sure the source data doesn't have multiple values in it?
if a.area_of_interest_landing__c == 'a;b'
and a.area_of_interest__c == 'b;c'

you're going to end up with b twice, because you didn't split the values up to put them in a set.
KeithlarsKeithlars
That's it.  Thanks.

Keith