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
Dimple SinghDimple Singh 

How to compare two set values?

Raj VakatiRaj Vakati

ou can use "containsAll" ..
Returns true if the set contains all of the elements in the specified set. The specified set must be of the same type as the original set that calls the method. 
Set<String> myString = new Set<String>{'a', 'b'};
Set<String> sString = new Set<String>{'c'};
Set<String> rString = new Set<String>{'a', 'b', 'c'};

Boolean result1, result2;
result1 = myString.addAll(sString);
system.assertEquals(true, result1);

result2 = myString.containsAll(rString);
System.assertEquals(true, result2);
https://salesforce.stackexchange.com/questions/108091/how-to-compare-two-sets-namely-set-a-and-set-b-while-both-contains-set-of-ids-th
 
Akshay_DhimanAkshay_Dhiman
Hi Dimple Singh,

You can try this way
 
Set<Id> setAIds = new set<Id>{'0039000001pJpRH', '0069000000K8YjG'};
Set<Id> setBIds = new set<Id>{'0039000001pJpRH'};

system.debug('====setAIds==='+setAIds);
system.debug('====setBIds==='+setBIds);

for(Id objId: setAIds){
    if(setBIds.contains(objId))
        setBIds.remove(objId);
}
system.debug('====setAIds==='+setAIds);
system.debug('====setBIds==='+setBIds);


Thank You
Akshay