I have set up some duplicate rules on account object. These rules have identified potential duplicate accounts. I need to retrieve these potential duplicate accounts in code. Is there a way to do this?
You can query the DuplicateRecordItem table for all records that have the same DuplicateRecordSet. First, query for all DuplicateRecordItem entries for the record(s) in question, then query for all DuplicateRecordItem entries for any of the DuplicateRecordSet entries for those DuplicateRecordItem entries. In this way, you'll have all of the record Id values for all potential duplicates.