I'm trying to see if the Ids in a set made up of Ids from trigger.old are in a map. Below is the for loop I put together to do this. If I add an Id to "uniqueSummary.contains('a1N1U000001kDcI')" I'm able to execute the code block. If I try to reference the keys in the map "if(!uniqueSummary.containsAll(summaryListOpen.KeySet()))" then the code block doesn't execute as expected.

for(Id u : uniqueSummary){
            CMRules__Email_Tracking_Summary__c sent = new CMRules__Email_Tracking_Summary__c(Id = u, CMRules__Sent__c = 0);
                    summaryListSent.put(sent.Id, sent);

It appears you have the comparison backwards. You want to check if the key set contains all the values of uniqueSummary, so summaryListOpen should be the object used for comparison:

if(summaryListOpen.keySet().containsAll(uniqueSummary)) {

To illustrate the difference, see the following:

Set<Integer> set1 = new Set<Integer> { 1, 3 };
Set<Integer> set2 = new Set<Integer> { 1, 3, 5, 7 };
Boolean set1ContainsAllset2 = set1.containsAll(set2); // false
Boolean set2ContainsAllset1 = set2.containsAll(set1); // true

Here, set2 contains all elements of set 1 (plus more), while set1 does not contain all of set2 (and obviously can't, because it has fewer elements).

Presumably, based on the variable names, uniqueSummary is smaller than summaryListOpen, therefore, it cannot possibly contain all the values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.