Understanding Salesforce Database.dmlOptions to improve efficiency
Author
April 25, 2023
The Salesforce platform provides a wide range of features to developers that help them create powerful and robust applications. One such feature is the Database.dmloptions class, which allows developers to specify additional options for DML (Data Manipulation Language) operations. DML operations are used to insert, update, and delete records in the Salesforce database The Database.dmloptions class provides a way to set additional options for these operations, such as specifying how to handle errors or controlling how triggers are fired. In this blog, we will explore the various options available in the Database.dmloptions class and how they can be used to improve the performance of your applications.
Database.SaveResult[] results = Database.insert(recordsToInsert, new Database.DMLOptions());
In this example, we are creating a new instance of the Database.DMLOptions class and passing it to the insert method. We are not setting any options in this case, so the default options will be used.
Setting the DML Options
Available DML Options the Database.dmloptions class provides several options that can be set for DML operations. Here are the available options:
Assignment Rule Header:
The Assignment Rule Header option allows you to specify whether assignment rules should be triggered for the records being inserted or updated. By default, the assignment rules are triggered, but you can set it to false to skip them. This can be useful if you want to manually assign records to users or teams.
Here are some of the actions that can be customized using Assignment Rule Header:
- UseDefaultRule
- AssignmentRuleId
In this example, we are using a specific assignment rule (specific Id), this rule we can get by querying the AssignmentRule sObject. While using this property do not specify useDefaultRule.
Duplicate Rule Header:
Duplicate Rule Header is a header object that can be included in a DML operation to override the default behaviour of Duplicate Rules. By using this header object, you can customize the actions taken when a duplicate record is detected.
Here are some of the actions that can be customized using Duplicate Rule Header:
- Allow Save
By default, if a Duplicate Rule identifies a potential duplicate record, Salesforce will block the creation of the record. However, by using Duplicate Rule Header, you can override this behavior and allow the record to be created.
To allow the record to be created, you can set the AllowSave parameter to true:
- RunAsCurrentUser
This property indicates whether duplicate rules run in context with the current user’s sharing or not. If it is set as true, then the duplicate rules results will not include record details for duplicates that are not available to the user.
Email Header:
This option allows you to specify whether to send email notifications for the records being inserted or updated. You can set it to true to send the notifications or false to skip them.
Some of the commonly used properties are:
- triggerUserEmail
This property indicates whether the email will be triggered that is sent to the user in the organization.
In this example, we are setting the Email Header option to not trigger email notifications to the user who initiated the DML operation.
triggerAutoResponseEmail
This property indicates whether the auto response rules will be triggered or not.
In this example, we are setting the triggerAutoResponseEmail as true so whenever we will perform DML operation on leads and cases, the auto response rule will be triggered.
- triggerOtherEmail
This property controls whether to trigger the email outside the organization or not.
OptAllOrNone:
This option allows you to specify whether to roll back the entire transaction if any records fail to insert, update, or delete.
You can set it to true to roll back the entire transaction or false to allow the successful records to be committed.
In this example, we are setting the Opt All Or None Child option to roll back the entire transaction if any child records fail.
We can keep it false if we want to perform operation partially.
Allow Field Truncation:
This option allows you to specify whether to truncate field values that are too long to fit in the database field. You can set it to true to allow truncation or false to throw an error if the value is too long.
In this example, we are setting the Allow Field Truncation option to truncate the field value if it’s too long.
Conclusion
In summary, the Database.dmloptions class provides a way to set additional options for DML operations in Salesforce. These options can be used to control how triggers are fired, handle errors, and set various other settings. By setting the appropriate options, you can customize the behavior of your DML operations and ensure that they perform as expected.
Pranshu Goyal, Director of Products at Mirekta, states: “We envision DSM to be used by every small to a medium-sized organization dealing with bad data and want to get rid of duplicates easily with no cost. We have faced issues dealing with duplicates in our organization. That inspired us to make a solution that is not only simple to use but can be used widely to make the organization’s data clean to make them more efficient and productive. We want DSM to be a solution for every organization looking for duplicate management capability better than the Salesforce out-of-the-box solution with no additional cost.”
Recent Posts
-
AI for Nonprofits: Boosting Fundraising with Salesforce Einstein, Agentforce, and Smarter InsightsShape25 Mar 2025 Use-case
-
AI-Powered Vaccination Scheduling with Einstein Copilot & Predictive AI21 Mar 2025 Use-case
-
Leveraging AI to Enhance Sales Effectiveness13 Mar 2025 Use-case
-
Revolutionizing Manufacturing with AI: Predictive Maintenance, Supply Chain Optimization, and More11 Mar 2025 E-Book
-
NetSuite for Manufacturing: Streamlining Operations and Solving Key Challenges07 Mar 2025 Blog
-
How to Build Your First Agent in Salesforce Agentforce24 Feb 2025 Blog
-
ERP vs Salesforce Revenue Cloud: Which One is Right for Your Business?24 Feb 2025 E-Book
-
Revolutionizing Manufacturing with Salesforce: A Playbook for Efficiency & Growth18 Feb 2025 E-Book
-
Salesforce 2025 Game-Changing Trends You Need to Know28 Jan 2025 Blog
-
Agentforce 2.0: Everything You Need to Know About the Latest Update22 Jan 2025 Blog
-
The Ultimate Guide to NetSuite Development: Tools and Techniques10 Jan 2025 Blog
-
How Salesforce Nonprofit Cloud Transforms Fundraising Strategies10 Jan 2025 Blog
-
The Impact of Salesforce Development Partners on Small and Medium Businesses08 Jan 2025 Blog
-
Key Questions to Ask When Hiring a NetSuite Development Partner08 Jan 2025 Blog
-
Salesforce Agentforce Demystified: Your Essential Guide08 Jan 2025 Blog
-
Salesforce and NetSuite Integration: Driving Business Efficiency with Precision06 Jan 2025 Blog
-
Everest Group has positioned Mirketa as an Aspirant in the report24 Dec 2024 Press Release
-
Salesforce Einstein20 Dec 2024 E-Book
-
Order to Cash Cycle with NetSuite20 Dec 2024 E-Book
-
Empower Your Marketing Strategy with Salesforce Marketing Cloud's Automation Studio Activities13 Dec 2024 Blog
-
Salesforce CPQ for Subscription-based Businesses10 Dec 2024 Blog
-
Unleashing the Magic of Einstein Prediction Builder10 Dec 2024 Blog
-
Customized Templates and Branding with Salesforce Experience Cloud10 Dec 2024 Blog
-
Unleashing the Power of Real- Time Reports and Dashboards in NPSP10 Dec 2024 Blog
-
Top 4 Salesforce Automation Tools in 202409 Dec 2024 Blog
-
Salesforce Service Cloud Implementation: The Ultimate Guide09 Dec 2024 Blog
-
Salesforce CRM Implementation Partner Enhancing Automation in Healthcare09 Dec 2024 Blog
-
Shorten Your Sales Cycle in 8 Steps: Salesforce CPQ Implementation Guide09 Dec 2024 Blog
-
Overcoming Top 5 Common Sales Challenges With Salesforce Revenue Cloud06 Dec 2024 Blog
-
Empowering Sales Teams with Einstein: 5 Proven Methods to Drive Sales Success05 Dec 2024 Blog
Categories
Featured by



