Apex API

Last published at: 2023-09-26 08:56:58 UTC
Delete

Duplicate Check's Apex API is only available in the Premium edition.

You can use our APEX API code to integrate Duplicate Check features into your own projects. 

dc3Api Methods

The following methods are available in the dc3Api class.

Search Methods

Map<String, List<dupcheck.dc3SearchResult>> doSearch (Sobject objectData)

Executes a search with the Duplicate Check search engine.
Input

  • objectData: instance of a Sobject class

Output
Map with search results. Where the Key in the Map contains the object Name.

Map<String, List<dupcheck.dc3SearchResult>> doSearch(Id objectId)

Executes a search with the Duplicate Check search engine.
Input

  • objectId : Id of an existing record in Salesforce.

Output
Map with search results. Where the Key in the Map contains the object Name.

Map<String, List<dupcheck.dc3SearchResult>> doSearch(Map<String, Object> objectData, String objectPrefix)

Executes a search with the Duplicate Check search engine.
Input

  • objectData: Map. Where the key contains the API Fieldname and the value contains the field value
  • objectPrefix: String which contains the object key prefix of the object you want to search on. (eg; Lead = '00Q').

Output
Map with search results. Where the Key in the Map contains the object Name.

Map<String, List<dupcheck.dc3SearchResult>> doSearch(Map<String, Object> objectData, String objectPrefix, String filter)

Executes a search with the Duplicate Check search engine.
Input

  • objectData: Map. Where the key contains the API Fieldname and the value contains the field value
  • objectPrefix: String which contains the object key prefix of the object you want to search on. (eg; Lead = '00Q').
  • filter: a query filter, such as 'FirstName = /'John/''.

Output
Map with search results. Where the Key in the Map contains the object Name.

Map<String, List<dupcheck.dc3SearchResult>> doSearch(Map<String, Object> objectData, String objectPrefix, String filter, Set<String> scenarioIds)

Executes a search with the Duplicate Check search engine.
Input

  • objectData: Map. Where the key contains the API Fieldname and the value contains the field value
  • objectPrefix: String which contains the object key prefix of the object you want to search on. (eg; Lead = '00Q').
  • filter: a query filter, such as 'FirstName = /'John/''.
  • scenarioIds: a Set of scenarioIds which are used for this search. The IDs can be found by hovering over the info icon after the scenario name in DC Setup.

Output
Map with search results. Where the Key in the Map contains the object Name.

Map<String, List<dupcheck.dc3SearchResult>> doSearchWithFilter (Sobject objectData, String filterDeveloperName)

Executes a search with the Duplicate Check search engine. br /> Input

  • objectData: instance of a Sobject class
  • filterDeveloperName: String with the developer name of the predefined filter which should be used to filter the results.

Output
Map with search results. Where the Key in the Map contains the object Name.

Map<String, List<dupcheck.dc3SearchResult>> doSearchWithFilter(Id objectId, String filterDeveloperName)

Executes a search with the Duplicate Check search engine.
Input

  • objectId : Id of an existing record in Salesforce.
  • filterDeveloperName: String with the developer name of the predefined filter which should be used to filter the results.

Output
Map with search results. Where the Key in the Map contains the object Name.

Map<String, List<dupcheck.dc3SearchResult>> doSearchWithFilter(Map<String, Object> objectData, String objectPrefix, String filterDeveloperName)

Executes a search with the Duplicate Check search engine.
Input

  • objectData: Map. Where the key contains the API Fieldname and the value contains the field value
  • objectPrefix: String which contains the object key prefix of the object you want to search on. (eg; Lead = '00Q').
  • filterDeveloperName: String with the developer name of the predefined filter which should be used to filter the results.

Output
Map with search results. Where the Key in the Map contains the object Name.

Map<String, List<dupcheck.dc3SearchResult>> doSearchWithFilter(Map<String, Object> objectData, String objectPrefix, String filterDeveloperName, Set<String> scenarioIds)

Executes a search with the Duplicate Check search engine.
Input

  • objectData: Map. Where the key contains the API Fieldname and the value contains the field value
  • objectPrefix: String which contains the object key prefix of the object you want to search on. (eg; Lead = '00Q').
  • filterDeveloperName: String with the developer name of the predefined filter which should be used to filter the results.
  • scenarioIds: a Set of scenarioIds which are used for this search. The Ids can be found by hovering over the info icon after the scenario name in DC Setup.

Output
Map with search results. Where the Key in the Map contains the object Name.

Search Example

// 1. Create Search Object
Lead ld = new Lead(FirstName='Test', LastName='TestName', Email='test@test.com');


// 2. Create Search Class
dupcheck.dc3Api api = new dupcheck.dc3Api(); 


// 3. Execute the search.
Map<String, List<dupcheck.dc3SearchResult>> searchResult = api.doSearch(ld); 


// 4. Debug the results.
if (searchResult.containsKey('00Q')) { 
  system.debug(searchResult.get('00Q'));
  for (dupcheck.dc3SearchResult firstLeadDuplicate : searchResult.get('00Q')) {
    system.debug(firstLeadDuplicate.getObjectName());
    system.debug(firstLeadDuplicate.getObjectPrefix());
    system.debug(firstLeadDuplicate.getDisplayField());
    system.debug(firstLeadDuplicate.score);
    system.debug(firstLeadDuplicate.scenarioScores); 
    system.debug(firstLeadDuplicate.objectData); 
  }   
}

Merge Methods

Boolean doMerge(List<Sobject> objectList)

Execute a merge according to the DC Merge Rules
Input

  • objectList: A list of Sobject which should be merged.

Output
Boolean: True when the merge has succeeded.

Boolean doMerge(List<Sobject> objectList, Sobject masterObject)

Execute a merge according to the DC Merge Rules
Input

  • objectList: A list of Sobject which should be merged.
  • masterObject: An sobject which contains at least the Id of the record which should be master. If you set fields on this masterobject, these will be updated into the master.

Output
Boolean: True when the merge has succeeded.

Sobject getMergeMaster(List<Sobject> objectList)

Return the master record according to the DC Merge Rules.
Input

  • objectList: A list of Sobject which should be merged.

Output
Sobject: the master record as this would be after the merge has succeeded. Note: it will only contain field data for fields that will be changed.

Sobject getMergeMaster(List<Sobject> objectList, Boolean populateReadOnlyFields)

Return the master record according to the DC Merge Rules, including fields that are read-only to the user.
Input

  • objectList: A list of Sobject which should be merged.
  • populateReadOnlyFields: whether fields that are read-only to the user should be shown (true) or not (false).

Output
Sobject: the master record as this would be after the merge has succeeded, including field data for fields that are read-only to the user. Note: it will only contain field data for fields that will be changed.

Match Methods

static Integer matchRecord(Sobject recordA, Sobject recordB)

Determine the matching score betweeen record A and Record B
Input

  • recordA: an Sobject containing the record to match
  • recordA: an Sobject containing the record to match with

Output
Integer: The matching score 0 to 100.

static Integer matchRecord(Sobject recordA, Sobject recordB, Set<Id> scenarioIds)

Determine the matching score betweeen record A and Record B
Input

  • recordA: an Sobject containing the record to match
  • recordA: an Sobject containing the record to match with
  • scenarioIds: a set of scenario ids to use when determining the matching score. These can be found in the DC Setup.

Output
Integer: The matching score 0 to 100.

Direct Process Methods

void doDirectProcess(Id recordId)

Starts an async execution of the Direct Processing feature for the specified record.
Input

  • recordId: The Id of the record to process.
void doDirectProcess(Id recordId, String filterDeveloperName)

Starts an async execution of the Direct Processing feature for the specified record.
Input

  • recordId: The Id of the record to process.
  • filterDeveloperName: The developer name of the predefined filter which should be used to filter the results.

Configuration Methods

static String exportConfiguration()

Exports the complete DC Configuration.
Output
A JSON string containing the configuration. This can be stored and used to import the configuration again.

static void importConfiguration(String jsonString)

Exports the complete DC Configuration.
Input

  • jsonString: A JSON string containing the configuration.

Index Methods

static Boolean doIndex(String objectPrefix)

Starts a complete indexing process for the provided object.
Input

  • objectPrefix: String containing the object prefix. (eg; Lead = '00Q').

Output
Boolean: If the process has started the results is true.

static Boolean doIndex(Set<Id> recordSet)

Starts the index for the provided record ids.
Input

  • recordSet: A set of Id's containing the records you want to index.

Output
Boolean: If the process has started the results is true.

void startIndexQueue()

Start the batch index queue. When records are added or still present in the queue.

dc3SearchResult -- Class Definition

data

  • Integer Score
  • Sobject objectData

Methods

getObjectName()
Returns the Object Name of the record in the objectData variable.

Return: String

getObjectPrefix()
Returns the Object Prefix of the record in the objectData variable.

    Return: String

getDisplayField()
Returns a Map with the field you want to display, this includes the actual field data.

    Return: Map<String, Object>

Sort()
Sorts a list containing dc3SearchResult based on score, highest score first.

dc3Config.ResultField -- Class Definition

data

  • String fieldName
  • String fieldLabel
  • Integer sortOrder
  • Id resultFieldId
  • Id recordTypeId

method

  • Sort()
    Sorts a list containing dc3Config.ResultField based on the sortOrder, lowest sortOrder first.

Testing the API

In order to get enough code coverage  you code needs to get some code coverage. The duplicate check api cannot deliver the correct answer when in testing context. Therefore the API calls needs to be mocked. Please see the example below.

 // 1. Create Search Object
Lead ld = new Lead(FirstName='Test', LastName='TestName', Email='test@test.com');


// 2. Create Search Class
dupcheck.dc3Api api = new dupcheck.dc3Api();
Map<String, List<dupcheck.dc3SearchResult>> searchResult;


// 3. Execute the search or create mock result when in testing context
if (test.isRunningTest()) {
   searchResult = new Map<String, List<dupcheck.dc3SearchResult>>();
   searchResult.put('00Q', new List<dupcheck.dc3SearchResult>());
   dupcheck.dc3SearchResult dup1 = new dupcheck.dc3SearchResult();
   dup1.score = 100;
   dup1.objectData = [SELECT ID, FIRSTNAME FROM LEAD WHERE FirstName = 'TEST' LIMIT 1];
   searchResult.get('00Q').add(dup1);
} else {
   searchResult = api.doSearch(ld);
}


// 4. Debug the results.
if (searchResult.containsKey('00Q')) { 
  system.debug(searchResult.get('00Q'));
  for (dupcheck.dc3SearchResult firstLeadDuplicate : searchResult.get('00Q')) {
    system.debug(firstLeadDuplicate.getObjectName());
    system.debug(firstLeadDuplicate.getObjectPrefix());
    system.debug(firstLeadDuplicate.getDisplayField());
    system.debug(firstLeadDuplicate.score);
    system.debug(firstLeadDuplicate.scenarioScores); 
    system.debug(firstLeadDuplicate.objectData); 
  }   
}