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

SFDC ADMIN
Everything is Configuration. Logical Data Diagramatic Approach Business Analysis Required Implementation the Architecture Internal Stack holders Discussions.

Difference Between Workflows, Process Builder, Triggers.
Difference Between Workflows, Process Builder, Triggers. Workflows: Which is Automated business proces with help of New Task, Email Alert, Field Update, Outbound Messages. Process Builder: Which is...

Before Take Salesforce Training Need To Ask Below Things
In every platform technology will be follow below things: i. Software Development Life Cycle--------SDLC having diffrent METHADOLOGIES (Salesforce SDLC -- Agile and Agile with SCRUM) What is the difference...

How to Learn salesforce easily?
Steps: 1.Know the course content. 2. Collect all materials. 3. Separate all materials into A.Admin B.Development C.Project. 4. Get the best trainer and follow him/her. 5. Update your skills with the help of all available resources.

Trigger Sceniors - session 2
Scenario3:- // Amount In Words before Insert, before update for(Quote qu : Trigger.New) { if(qu.amount_in_words__c!=null) { qu.Converted_Amount_In_Words__c = ConvertRupees.ConvertFun((qu.amount_in_words__c)); ...
S
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