UrbanPro
true

Learn Salesforce Administrator from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

What is Mixed-DML-Operation Error And How To Avoid?

Kumar
05/08/2017 0 0

If we perform DML operation on standard/custom object and global objects(User, UserRole, Group, GroupMember, Permission Set, etc...) in same transaction this error will come.

To avoid this error, we should perform DML operation on standard/custom object records in a different transaction.

In general all the apex classes and apex triggers execute synchronously (execute immediately).

If we perform DML operation on standard/custom object records asynchronously (execute in future context), we can avoid MIXED-DML-OPERATION error.

To execute logic asynchronously keep the logic in an apex method (in a separate apex class, not in same apex trigger) which is decorated with @future annotation.

See the below example:

Note: To analyse the code copy it and paste it in notepad for the convenience.

 public class TriggerUtility {

  /*                    

  1. Following future method execute asynchronously (whenever server is free it will execute in future context).

  2. We should not declare @future method in Apex Trigger.

  3. @future method should be always static.

  4. @future method accepts only primitive data types (Integer, String, Boolean, Date, etc...) as parameters and it won't accept

  non-primitive data types (sObject,Custom Objects and standard Objects etc.. ) as parameters.

  5. @future method should not contain return type. Always it should be void.

  6. From an apex trigger we can make only make asynchronous call outs. To make call out we should include "callout = true" beside the future @annotation.

  7. We cannot perform synchronous call outs from Apex Trigger.

  */

  //Below is the example for the future method -

  @future(callout = true)

  public static void processAsync(primitive parameters) {

   //Logic to insert/update the standard/custom object.

  }

 }

0 Dislike
Follow 0

Please Enter a comment

Submit

Other Lessons for You

What Are The Map Methods Available In Apex?
//Map holds key and value pair. //Syntax: Map mapName = new Map(); /*Map countryISTCodeMap = new Map(); countryISTCodeMap.put('India','91'); countryISTCodeMap.put('USA','001'); countryISTCodeMap.put('India','911');//replaces...

What Is The Order Of Execution In Salesforce?
We are creating validation rules, workflow rules, assignment rules, auto-responsive rules, escalation ruels and apex triggers etc. If the condition is same for all the rules which will execute first and...

Salesforce OWD
Imagine you have two users. Both are in the same profile, which allows them to Create, Edit object XYZ. But these two users are in different parts of the role hierarchy.If User A Creates an XYZ, can user...

What Is SOQL And SOSL?
1. SOQL: Salesforce Object Query Language SOQL: Salesforce Object Query Language SOQL Purpose: To fetch info. from an object and related objects. We can write query on one object while querying...

What Is Batch Apex And Its Methods ?
1. We can call the apex code by creating object for the class (or) if the variables or methods are static then we can call with class name. Apex Code in the trigger will execute automatically for...
X

Looking for Salesforce Administrator Classes?

The best tutors for Salesforce Administrator Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Salesforce Administrator with the Best Tutors

The best Tutors for Salesforce Administrator Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more