You need to sign in to do that
Don't have an account?
RICARDO 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);
}
}
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);
}
}
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
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