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

Assigning One permission to multiple users automatically without any manual work.
Hi Friends,I recently came across below new things I did in my project. Hope it helps you too.Description :How to Assign one permission set to multiple Users ? For example: If I want to assign ONE permission...

Importance of Pagelayout in salesforce
𝐖𝐡𝐚𝐭 𝐚𝐫𝐞 𝐟𝐞𝐚𝐭𝐮𝐫𝐞𝐬 𝐭𝐡𝐚𝐭 𝐜𝐚𝐧 𝐛𝐞 𝐜𝐨𝐧𝐭𝐫𝐨𝐥𝐥𝐞𝐝 𝐮𝐬𝐢𝐧𝐠 𝐩𝐚𝐠𝐞 𝐋𝐚𝐲𝐨𝐮𝐭?>>Control which fields, lists of related records, and custom links userscan see>>Customize...

What is a standard direct mail workflow?
Many nonprofits have been doing direct mail for years or even decades, so we’ve all developed our own particular processes. Every organization is unique and has different direct mail needs and goals....
T

Thinksoft Infotech

0 0
0

Trigger Sceniors - session 5
//Trigger Check Duplicate before insert, before update Set leadid = new Set(); Map<String,Lead> phonemap = new Map<String,Lead>(); Map<String,Lead> emailmap = new Map<String,Lead>();...
S

Difference Between Data Loader And Import Wizard In Salesforce
Difference between Dataloader and Import Wizard in Salesforce: Dataloader Import Wizard It supports more than 50000 records. It supports only up to 50000. It supports...
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