DMLOptions Class
Enables you to set options related to DML operations.
Database.DMLOptions is only available for Apex saved against API versions 15.0 and higher. DMLOptions settings take effect only for record operations performed using Apex DML and not through the Salesforce user interface. The DMLOptions class has three child options.
- DML Child Options: DmlOptions.AssignmentRuleHeader—Enables setting assignment rule options. DmlOptions.DuplicateRuleHeader—Determines options for using duplicate rules to detect duplicate records. Duplicate rules are part of the Duplicate Management feature. DmlOptions.EmailHeader—Enables setting email options.
See Also
The following are properties for DmlOptions.
-
Specifies the truncation behavior of large strings.
-
Specifies the assignment rule to be used when creating a case or lead.
-
Specifies additional information regarding the automatic email that gets sent when an events occurs.
-
Specifies the language of any labels that are returned by Apex.
-
Specifies whether the operation allows for partial success.
Specifies the truncation behavior of large strings.
public Boolean allowFieldTruncation {get; set;}
Type: Boolean
In Apex saved against API versions previous to 15.0, if you specify a value for a string and that value is too large, the value is truncated. For API version 15.0 and later, if a value is specified that is too large, the operation fails and an error message is returned. The allowFieldTruncation property allows you to specify that the previous behavior, truncation, be used instead of the new behavior in Apex saved against API versions 15.0 and later.
Specifies the assignment rule to be used when creating a case or lead.
public Database.DmlOptions.Assignmentruleheader assignmentRuleHeader {get; set;}
Type: Database.DMLOptions.AssignmentRuleHeader
DMLOption.AssignmentRuleHeader.useDefaultRule affects only the default assignment rule and does not disable other existing assignment rules on the object.
The Database.DMLOptions object supports assignment rules for cases and leads, but not for accounts.
Specifies additional information regarding the automatic email that gets sent when an events occurs.
public Database.DmlOptions.EmailHeader emailHeader {get; set;}
Type: Database.DMLOptions.EmailHeader
The Salesforce user interface allows you to specify whether or not to send an email when the following events occur.
- Creation of a new case or task
- Conversion of a case email to a contact
- New user email notification
- Lead queue email notification
- Password reset
In Apex saved against API version 15.0 or later, the Database.DMLOptions emailHeader property enables you to specify additional information regarding the email that gets sent when one of the events occurs because of the code’s execution.
Specifies the language of any labels that are returned by Apex.
public Database.DmlOptions.LocaleOptions localeOptions {get; set;}
Type: Database.DMLOptions.LocaleOptions
The value must be a valid user locale (language and country), such as de_DE or en_GB. The value is a String, 2-5 characters long. The first two characters are always an ISO language code, for example ‘fr’ or ‘en.’ If the value is further qualified by a country, then the string also has an underscore (_) and another ISO country code, for example ‘US’ or ‘UK’. For example, the string for the United States is ‘en_US’, and the string for French Canadian is ‘fr_CA’.
Specifies whether the operation allows for partial success.
public Boolean optAllOrNone {get; set;}
Type: Boolean
If optAllOrNone is set to true, all changes are rolled back if any record causes errors. The default for this property is false and successfully processed records are committed while records with errors aren’t. If optAllOrNone is set to false and a record fails, the remainder of the DML operation can still succeed. You must iterate through the returned results to identify which records succeeded or failed.
This property is available in Apex saved against Salesforce API version 20.0 and later.