0
votes

I recently wrote an API to implement Account/Contact Duplicate/Matching rules for a connected app. It all works fine.

It does the same thing that Salesforce does for these rules. It pretty much follows this example code: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Datacloud_DuplicateResult.htm

I'm now trying to write a test class for this but I'm hitting a roadblock.

I need a way to do one of two things:

  1. Create Duplicate and Matching rules through Apex code within the test. I would create them, run the test, then delete them.

  2. Turn Duplicate and Matching rules on and off through Apex code within the test. Same general idea but I could create them beforehand in our testing org.

As far as I can tell there is no way to do this. Am I missing something here?

If this isn't possible then how do I get test coverage on my class. It will only get full code coverage if the call to Database.Insert actually fails with DuplicateErrors.

Edit: I should add that having rules always on and bypassing them with DMLHeader for testing is not an option.

1

1 Answers

0
votes

I would say you don't have to create the Duplicate or Matching rules in Apex (not even sure if it is possible). In fact, you should rely on having the Duplicate rules that you've configured in Salesforce. So you should just try to generate the duplicate Salesforce as the Duplicate Rules should trigger also when running the test.