Most of us received such error "MIXED DML OPERATION"
while running test classes.
What is
Mixed DML Error?
DML operations on certain
sObjects can’t be mixed with other sObjects in the same transaction. This is
because some sObjects affect the user’s access to records in the organization.
These types of sObjects must be inserted or updated in a different transaction
to prevent operations from happening with incorrect access level permissions.
For example, you can’t update an account and a user role in a single
transaction. However, there are no restrictions on delete DML operations.
Source: Mixed
DML
How to avoid
in your Test class?
Here is the syntax to avoid test class errors in Mixed DML
Operation salesforce. If you are inserting Setup and Non-Setup object means use
System.runAs() and pass the current user information, you will get rid of from
the Mixed DML errors.
- @isTest
- public class ShowEmailUtilsTest
- {
- Public static testmethod void Test_ShowEmailUtils()
- {
- User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
- System.runAs (thisUser)
- {
- // Add your test class content here
- }
- }
- }
Thanks for the blog article.Thanks Again. Keep writing.salesforce online training in hyderabad
ReplyDeletesalesforce online training hyderabad
Hello Everyone,
ReplyDeleteWelcome to the future! Financing made easy with Prof. Mrs. DOROTHY LOAN INVESTMENTS
Have you been looking for financing options for your new business plans, Are you seeking for a loan to expand your existing business, Do you find yourself in a bit of trouble with unpaid bills and you don’t know which way to go or where to turn to? Have you been turned down by your banks? MRS. DOROTHY LOAN INVESTMENTS says YES when your banks say NO. Contact us as we offer financial services at a low and affordable interest rate of 2% for long and short term loans. Interested applicants should contact us for further loan acquisition procedures via profdorothyinvestments@gmail.com
Services rendered include:
*Refinancing Loans
* Car Loan
*Truck Loans
* Home Loan
* Mortgage Loan
* Debt Consolidation Loan
* Business Loan [secure and unsecured]
* Personal Loan [secure and unsecured]
* Students Loan and so many others.
For more info; Contact us via Email: profdorothyinvestments@gmail.com
With Prof. Mrs. DOROTHY LOAN INVESTMENTS. you can say goodbye to all your financial crisis and difficulties as we are certified, trustworthy, reliable, efficient, fast and dynamic