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
Micky MMicky M 

Comparing Lists

Hi all,

I have a problem where i have to compare two lists, however each list will be over 50,000 records at some point, does anyone know the best way to go about this? im a bit stumped as i dont want to start bumping into govenor limits and all that stuff. Any ideas would be great thx!
Sagar PareekSagar Pareek
Map<String, Obj__c> objMap1 = new Map<String, Obj__c>();
Map<String, Obj__c> objMap2 = new Map<String, Obj__c>();

// List 1
for(Obj__c o : list1)
{
    objMap1.put(o.UniqueName__c, o);
}

// List 2
for(Obj__c o : list2)
{
    objMap2.put(o.UniqueName__c, o);
}

// Now you can easily check if that value is in your map by doing.
objMap1.containsKey('WhateverYouWantToCompare');
// or
objMap2.containsKey(newObj.UniqueName__c);

// ... do your logic

 
Micky MMicky M
Hi thanks for your help, thing i was wondering was how would this cope with the 50000 record limit in lists? how would i select say 60 records in two seperate lists to process them ... does that make sense?