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

Compare two SET<ID>

I want to know what is the best way to compare two set <id>
 Set <id> a = new Set<id>();   
 Set <id> b = new Set<id>();  
Set <id> accToDeactivate = new Set<id>();    

I want to know if the any of the Ids on  are on b, if the are not I want add those ids to another set
I tried this code but is not working, it is getting me all the id on b.
for(Id objId: b){
            if(a.contains(objId)) {
//do nothing 
Dushyant SonwarDushyant Sonwar
Hi Ricardo,

You can use equals(set2) method of set Class.
Hope this helps
Preya VaishnaviPreya Vaishnavi
Hey Ricardo,

If you are checking whether the set 'a' contains a value in set b,your code is correct.Check the records that you looped through by using debug statement