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
RICARDO PALMARICARDO PALMA 

Compare two SET<ID>

Hi,
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.
 If
for(Id objId: b){
            if(a.contains(objId)) {
//do nothing 
           }else{
 accToDeactivate.add(objId);
            }
      }
Dushyant SonwarDushyant Sonwar
Hi Ricardo,

You can use equals(set2) method of set Class.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_set.htm
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