DMLOptions.DuplicateRuleHeader Class
Determines options for using duplicate rules to detect duplicate records. Duplicate rules are part of the Duplicate Management feature.
The following example shows how to save an account record that’s been identified as a duplicate. To learn how to iterate through duplicate errors, see DuplicateError Class
The following are properties for DMLOptions.DuplicateRuleHeader.
-
For a duplicate rule, when the Alert option is enabled, bypass alerts and save duplicate records by setting this property to
true. Prevent duplicate records from being saved by setting this property tofalse. -
Determine whether sharing rules for the current user are enforced when duplicate rules run (
true) or not (false). If no sharing rules are specified, Apex code runs in user mode and sharing rules for the current user are enforced.
For a duplicate rule, when the Alert option is enabled, bypass alerts and save duplicate records by setting this property to true. Prevent duplicate records from being saved by setting this property to false.
public Boolean allowSave {get; set;}
Type: Boolean
This example shows how to save an account record that’s been identified as a duplicate. dml.DuplicateRuleHeader.allowSave = true means the user should be allowed to save the duplicate. To learn how to iterate through duplicate errors, see DuplicateError Class.
Determine whether sharing rules for the current user are enforced when duplicate rules run (true) or not (false). If no sharing rules are specified, Apex code runs in user mode and sharing rules for the current user are enforced.
public Boolean runAsCurrentUser {get; set;}
Type: Boolean
If specified as true, duplicate rules run for the current user, which ensures users can’t view duplicate records that aren’t available to them.
Use runAsCurrentUser = true to detect duplicates when converting leads to contacts.
This example shows how to set options so that duplicate rules run for the current user when saving a new account.