Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
DMLOptions.DuplicateRuleHeader Class
Namespace
Example
1Database.DMLOptions dml = new Database.DMLOptions();
2dml.DuplicateRuleHeader.allowSave = true;
3dml.DuplicateRuleHeader.runAsCurrentUser = true;
4Account duplicateAccount = new Account(Name='dupe');
5Database.SaveResult sr = Database.insert(duplicateAccount, dml);
6if (sr.isSuccess()) {
7 System.debug('Duplicate account has been inserted in Salesforce!');
8}DMLOptions.DuplicateRuleHeader Properties
The following are properties for DMLOptions.DuplicateRuleHeader.
allowSave
Signature
public Boolean allowSave {get; set;}
Property Value
Type: Boolean
Example
1Database.DMLOptions dml = new Database.DMLOptions();
2dml.DuplicateRuleHeader.allowSave = true;
3dml.DuplicateRuleHeader.runAsCurrentUser = true;
4Account duplicateAccount = new Account(Name='dupe');
5Database.SaveResult sr = Database.insert(duplicateAccount, dml);
6if (sr.isSuccess()) {
7 System.debug('Duplicate account has been inserted in Salesforce!');
8}runAsCurrentUser
Signature
public Boolean runAsCurrentUser {get; set;}
Property Value
Type: Boolean
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
1Database.DMLOptions dml = new Database.DMLOptions();
2dml.DuplicateRuleHeader.allowSave = true;
3dml.DuplicateRuleHeader.runAsCurrentUser = true;
4Account duplicateAccount = new Account(Name='dupe');
5Database.SaveResult sr = Database.insert(duplicateAccount, dml);
6if (sr.isSuccess()) {
7 System.debug('Duplicate account has been inserted in Salesforce!');
8}