Show:                  

DuplicateRecordSetTriggerHandler

Trigger Handler for DuplicateRecordSet
Signature
public inherited sharing class DuplicateRecordSetTriggerHandler
See
Author
Since
  • 04/19/2021 Initial Version
  • 04/19/2021 Moved deletion of sets to the Item trigger handler for more control and to delete 0 record count sets
  • 02/28/2022 Static to instance trigger handler methods
  • 09/14/2022 Salesforce may be auto-deleting single-record sets, so setting allOrNothing to false
  • DuplicateRecordSetTriggerHandler Methods

    deleteSingleRecordSetsFuture(candidatesToDelete)

    Future delete DuplicateRecordSet records with only 1 DuplicateRecordItem
    Signature
    @future
    public static void deleteSingleRecordSetsFuture(Set<Id> candidatesToDelete)
    Parameters
    candidatesToDelete
    Type: Set<Id>
    Queried DuplicateRecordSet records with 1 DuplicateRecordItem
    Author

    deleteUnnecessaryRecordSets(candidatesToDelete)

    Declare deletion in a synchronous method so it can be called from either the main handler class or an asychronous method. (DRY)
    Signature
    private static void deleteUnnecessaryRecordSets(Set<Id> candidatesToDelete)
    Parameters
    candidatesToDelete
    Type: Set<Id>
    DuplicateRecordSet IDs to delete

    findSingleRecordSets(newRecords, oldRecordsMap)

    Query for all single-item DuplicateRecordSet records
    First we exclude DRS records where the DRI count was and is zero. This allows us to instantiate the record. We don't know why DRS records are also updated when they are created, but that's the situation.
    Then we delete DRS records where RecordCount < 2 (0 or 1) and can do so because we allowed the creation of the DRS.
    Signature
    public void findSingleRecordSets(List<DuplicateRecordSet> newRecords, Map<Id, DuplicateRecordSet> oldRecordsMap)
    Parameters
    newRecords
    Type: List<DuplicateRecordSet>
    Trigger.new
    oldRecordsMap
    Type: Map<Id, DuplicateRecordSet>
    Trigger.oldMap
    Author

    handleTrigger(newRecords, oldRecords, newRecordsMap, oldRecordsMap, triggerEvent)

    Handle all trigger records
    Signature
    public void handleTrigger( List<DuplicateRecordSet> newRecords, List<DuplicateRecordSet> oldRecords, Map<Id, DuplicateRecordSet> newRecordsMap, Map<Id, DuplicateRecordSet> oldRecordsMap, System.TriggerOperation triggerEvent )
    Parameters
    newRecords
    Type: List<DuplicateRecordSet>
    Trigger.new
    oldRecords
    Trigger.old
    newRecordsMap
    Type: DuplicateRecordSet>
    Trigger.newMap
    oldRecordsMap
    Type: DuplicateRecordSet>
    Trigger.oldMap
    triggerEvent
    Trigger context enum
    Author