You need to sign in to do that
Don't have an account?
Error throwing on trigger
Hi,
i AM GETTING THE BELOW ERROR when trying to save a record.
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger GroupCreation caused an unexpected exception, contact your administrator: GroupCreation: execution of AfterDelete caused by: System.DmlException: Delete failed. First exception on row 0 with id 00Gg0000000RxOYEA0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): Group, original object: IA_Team__c: []: Trigger.GroupCreation: line 83, column 1".
Trigger GroupCreation on IA_Team__c (after insert,after update,after delete) { Group grp = new Group(); list<Group> gplist=new list<Group>(); list<IA_Team__c> ialist=new list<IA_Team__c>(); if(trigger.isinsert) { set<id> memids = new set<id>(); for(IA_Team__c ev:Trigger.New) memids.add(ev.id); for(IA_Team__c ia:[select Name,Public_Group_Name__c from IA_Team__c where id in:memids]) { grp.Name = ia.Name; System.debug('@@@@@@@@@@@@@'+ grp.id); grp.DeveloperName = ia.Public_Group_Name__c; ia.Team_Linked_To_Group__c=True; ia.Unique_Group_Id__c=grp.Id; ialist.add(ia); gplist.add(grp); } if(!gplist.isempty()) { insert gplist; update ialist; } } if(trigger.isdelete) { set<string> memname = new set<string>(); Map<string,string> mgroups2 = New Map<string,string>(); for(IA_Team__c ev:Trigger.Old) { memname.add(ev.Name); mgroups2.put(ev.Name,ev.Name); } list<Group> resultlist=new list<Group >([select Name,DeveloperName from Group where Name in:memname]); list<Group> uplist=new list<Group>(); for (Integer i = 0; i < Trigger.oldMap.size(); i++) { if(mgroups2.containsKey(Trigger.old[i].Name)) { mgroups2.put(Trigger.old[i].Name,Trigger.oldMap[i].Name); } } for (Integer i = 0; i < resultlist.size(); i++) { if(mgroups2.containsKey(resultlist[i].Name)) { resultlist[i].Name=mgroups2.get(resultlist[i].Name); resultlist[i].DeveloperName=mgroups2.get(resultlist[i].Name); uplist.add(resultlist[i]); } } delete uplist; } }
Thanks in Advance.
Hi,
There you cannot perform DML on what salesforce calls setup objects(Group in this case) and non-setup object in the same context. To avoid thix context problem, perform this DML operation in FUTURE as following--
Please go through following tutorial:
1. http://www.tgerm.com/2012/04/mixeddmloperation-dml-operation-on.html
2. http://boards.developerforce.com/t5/Apex-Code-Development/Critical-bug-in-Apex-code-MIXED-DML-OPERATION-prevents-Users/m-p/77909
/**If this post helps you then please don't forget to give me kudo's by clicking star aside and mark it as a solution.***/
Thanks
www.grazitti.com