---
schema_version: "1"
id: 1f7f16a15a5a3158971c362b529c9a8c679b794cd3d93bb4330e1ffb149f55fc
title: DMLOptions.DuplicateRuleHeader Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_class_Database_DMLOptions_DuplicateRuleHeader.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Database_DMLOptions_DuplicateRuleHeader.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 6e86fbb619b4ebef65fa28049ae883778c2d77df073d0c1b6ba534a7a940069f
description: Determines options for using duplicate rules to detect duplicate records. Duplicate rules are part of the Duplicate Management feature.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.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.
---
# DMLOptions.DuplicateRuleHeader Class

Determines options for using duplicate rules to detect duplicate records. Duplicate rules are part of the Duplicate Management feature.

## Namespace

[Database](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_Database.htm "The Database namespace provides classes used with DML operations.")

## Example

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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Database_DuplicateError.htm#apex_class_Database_DuplicateError "Contains information about an error that occurred when an attempt was made to save a duplicate record. Use if your organization has set up duplicate rules, which are part of the Duplicate Management feature.")

Database.DMLOptions dml = new Database.DMLOptions(); 
dml.DuplicateRuleHeader.allowSave = true;
dml.DuplicateRuleHeader.runAsCurrentUser = true;
Account duplicateAccount = new Account(Name='dupe');
Database.SaveResult sr = Database.insert(duplicateAccount, dml);
if (sr.isSuccess()) {
	System.debug('Duplicate account has been inserted in Salesforce!');
}

- **[DMLOptions.DuplicateRuleHeader Properties](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Database_DMLOptions_DuplicateRuleHeader.htm#apex_Database_DMLOptions_DuplicateRuleHeader_properties)**

## DMLOptions.DuplicateRuleHeader Properties

The following are properties for DMLOptions.DuplicateRuleHeader.

- **[allowSave](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Database_DMLOptions_DuplicateRuleHeader.htm#apex_Database_DMLOptions_DuplicateRuleHeader_AllowSave)**  
    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.
- **[runAsCurrentUser](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Database_DMLOptions_DuplicateRuleHeader.htm#apex_Database_DMLOptions_DuplicateRuleHeader_runAsCurrentUser)**  
    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.

### allowSave

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.

#### Signature

public Boolean allowSave {get; set;}

#### Property Value

Type: [Boolean](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_boolean.htm#apex_methods_system_boolean "Contains methods for the Boolean primitive data type.")

#### Example

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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Database_DuplicateError.htm#apex_class_Database_DuplicateError "Contains information about an error that occurred when an attempt was made to save a duplicate record. Use if your organization has set up duplicate rules, which are part of the Duplicate Management feature.").

Database.DMLOptions dml = new Database.DMLOptions(); 
dml.DuplicateRuleHeader.allowSave = true;
dml.DuplicateRuleHeader.runAsCurrentUser = true;
Account duplicateAccount = new Account(Name='dupe');
Database.SaveResult sr = Database.insert(duplicateAccount, dml);
if (sr.isSuccess()) {
	System.debug('Duplicate account has been inserted in Salesforce!');
}

### runAsCurrentUser

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.

#### Signature

public Boolean runAsCurrentUser {get; set;}

#### Property Value

Type: [Boolean](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_boolean.htm#apex_methods_system_boolean "Contains methods for the Boolean primitive data type.")

#### Usage

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.

#### Example

This example shows how to set options so that duplicate rules run for the current user when saving a new account.

Database.DMLOptions dml = new Database.DMLOptions(); 
dml.DuplicateRuleHeader.allowSave = true;
dml.DuplicateRuleHeader.runAsCurrentUser = true;
Account duplicateAccount = new Account(Name='dupe');
Database.SaveResult sr = Database.insert(duplicateAccount, dml);
if (sr.isSuccess()) {
	System.debug('Duplicate account has been inserted in Salesforce!');
}