You need to sign in to do that
Don't have an account?
Adriana Voyce
MIXED_DML_OPERATION... System.runAs
I created a trigger, and it works great in Sandbox, but when I launched it to production I receieved the following error:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger autostaff caused an unexpected exception, contact your administrator: autostaff: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): Staff__c, original object: User: []: Trigger.autostaff: line 19, column 1
My trigger is written as follows:If creates a record on the staff object when a user is created
trigger autostaff on User (after insert) {
List <Staff__c> newstaff = new list <Staff__c> ();
for (User U : Trigger.new){
Staff__c Staff = new Staff__c();
Staff.Employee__c = U.ID;
Staff.Name = U.Full_Name__c;
newstaff.add(Staff);
}
insert newStaff;
}
From what I have read I need a to add System.runAs as part of my code, but I am not sure how that should be writttten...
Any help is appreaciated.... Please and thank you :)
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger autostaff caused an unexpected exception, contact your administrator: autostaff: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): Staff__c, original object: User: []: Trigger.autostaff: line 19, column 1
My trigger is written as follows:If creates a record on the staff object when a user is created
trigger autostaff on User (after insert) {
List <Staff__c> newstaff = new list <Staff__c> ();
for (User U : Trigger.new){
Staff__c Staff = new Staff__c();
Staff.Employee__c = U.ID;
Staff.Name = U.Full_Name__c;
newstaff.add(Staff);
}
insert newStaff;
}
From what I have read I need a to add System.runAs as part of my code, but I am not sure how that should be writttten...
Any help is appreaciated.... Please and thank you :)
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000Ah6dIAC
For more help visit https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dml_non_mix_sobjects.htm