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
vijendahr kvijendahr k 

Compare list of record with single record in salesforce

Hello All, 

  i have scenairo, where i have to compare with single record with list of records and if i found duplicate record i will have to return duplicate record.

 Example : List<account> listAcc= [select id, name, type,startdate, enddate, designation, ( select id , name , email, from contact), (select name, id, stage from oppty) from account]

  Account  acc= [select id, name, type,startdate, enddate, designation, ( select id , name , email, from contact), (select name, id, stage from oppty) from account where id='XXXXXXXX'];

now i have to compare account (acc) record with all the list of records from listAcc  data with parent and child records. if i found  same record in then i have to return duplicate record found. 

Thanks 


 
Glyn Anderson 3Glyn Anderson 3
What constitutes a "match" when comparing two records?  If it's that they have the same ID (i.e. they are literally the same record), then that's an easy task.  If you're looking for "duplicates" (i.e. records with the same name, email or other fields, but different IDs), then that's more difficult.  What exactly are the criteria for a match?
Sukanya BanekarSukanya Banekar
Hi,
If you want to compare list of records with single record, you can put the records in set and use method of set/ for e.g
set<Account> setAcc= //some set
Account acc;//some account
if(setAcc.Contains(acc)){
   return acc;
}

Let me know if this helps