• Tuyen Hoang 10
  • NEWBIE
  • -1 Points
  • Member since 2023

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Hi Community, 
 

I'm new to developing and I'm keen to learn the best way to compare two collections for future use on a trigger or method. 

For example for an investigation into org missing data if I wanted to compare Leads and Accounts to check which Leads had matching email addresses with Accounts but other personal information was diffrerent. 

At the moment I only know how to do this with two for loops but there must be a better way? possibly using maps or a map and list?

Account[] personalAccounts = [SELECT Id, FirstName, LastName, Phone, PersonMobilePhone, PersonEmail, EmployerCode__c, DOB__c FROM Account WHERE LastName != null AND PersonEmail != null AND DOB__c != null];

Lead[] leads = [SELECT Id, FirstName, LastName, Phone, MobilePhone, Email, Employer_Code__c, DOB__c FROM Lead WHERE Email != null AND DOB__c != null];

Sudo code

for Leads {
  for Accounts {
   If (Lead.email == Account.PersonalEmail && Lead.DOB__c != Account.DOB__c && Lead.EmployerCode__c != Account.EmployerCode__c etc )

  cleanUpMap.put(Lead.Id, Account.Id);

}
}

Appreciate the help, sorry for the terrible code.