You need to sign in to do that
Don't have an account?
Rbn
Help on trigger
Hi ..
I am getting the below error when trying to save the record
Error: EventObjectSync: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: Standard_Event__c duplicates value on record with id: a0Vg0000000URsh: [] Trigger.EventObjectSync: line 17, column 1
trigger::
trigger EventObjectSync on Event(After Insert,After Update) { list<Event_Object__c> eventlist2= new list<Event_Object__c>(); list<id> eventids= new list<id>(); map<id,Event_Object__c> custeventinserted = new map<id,Event_Object__c>(); if (EventObjectSyncClass.check){ list<Event_Object__c> eventlist = new list<Event_Object__c>(); list<UserAccountTeamMember> ues= new list<UserAccountTeamMember>(); list<Event_Object__Share> evntObjShare2 = new list<Event_Object__Share>(); for (integer a=0 ; a<Trigger.new.size() ; a++) { eventlist.add(EventObjectSyncClass.insertCustom(Trigger.new[a])); ues = [select id,UserId,TeamMemberRole,AccountAccessLevel from UserAccountTeamMember where OwnerId = :Trigger.new[a].OwnerId ]; } EventObjectSyncClass.check=False; Insert eventlist; for(UserAccountTeamMember a :ues){ Event_Object__Share evntObjShare = new Event_Object__Share(); string str1=''; string str2=''; str1=eventlist[0].id; str2=a.UserId; evntObjShare.ParentId = eventlist[0].id; evntObjShare.UserOrGroupId = a.UserId; evntObjShare.AccessLevel = 'Edit'; evntObjShare2.add(evntObjShare); evntObjShare = new Event_Object__Share(); } if(evntObjShare2.size()>0){ try{ //insert tskObjShare2; list<Database.SaveResult> sr = Database.insert(evntObjShare2,false); } catch (DmlException de) { Integer numErrors = de.getNumDml(); for(Integer i=0;i<numErrors;i++) { System.debug('getDmlFields=' + de.getDmlFields(i)); System.debug('getDmlMessage=' + de.getDmlMessage(i)); } } } } if (Trigger.isUpdate){ if (EventObjectSyncClass.check){ eventids= new list<id>(); custeventinserted = new map<id,Event_Object__c>(); for (integer a=0 ; a<Trigger.new.size() ; a++) { if(Trigger.new[a].TaskTemplateId__c!=null){ eventids.add(Trigger.new[a].TaskTemplateId__c); } } if(eventids.size()>0){ eventlist2=[select id,Subject__c,Description__c,Start__c,End__c,Assigned_To__c,Type__c,Reason__c,IsAllDayEvent__c,Show_Time_As__c,Location__c,Priority__c,What__c,Who__c,Private__c,Email__c,Phone__c,Reminder__c from Event_Object__c where id in : eventids]; for(Event_Object__c ta:eventlist2){ custeventinserted.put(ta.id,ta); } eventids= new list<id>(); eventlist2= new list<Event_Object__c>(); } for (integer a=0 ; a<Trigger.new.size() ; a++) { eventlist2.add(EventObjectSyncClass.Updatecustom(custeventinserted.get(Trigger.new[a].TaskTemplateId__c),Trigger.new[a])); } EventObjectSyncClass.check=False; update eventlist2; } } }
Public class EventObjectSyncClass{ Public static boolean check=True; Public static Event_Object__c Updatecustom(Event_Object__c CustEvent,Event StdEvent){ if(StdEvent.owner__c != null){ CustEvent.ownerid=StdEvent.owner__c; } if(StdEvent.Subject != null){ CustEvent.Subject__c=StdEvent.Subject; } if(StdEvent.Type != null){ CustEvent.Type__c=StdEvent.Type; } /* if(StdEvent.Description != null){ CustEvent.Description=StdEvent.Description; CustEvent.Description=CustEvent.Description+' This was created on be half of other employee '; }else { string str=' This was created on be half of other employee '; str=str+StdEvent.Owner.Name; CustEvent.Description=str; }*/ if(StdEvent.Description != null){ CustEvent.Description__c=StdEvent.Description; } if(StdEvent.Act_Type__c != null){ CustEvent.Reason__c=StdEvent.Act_Type__c; } if(StdEvent.IsAllDayEvent != null){ CustEvent.IsAllDayEvent__c=StdEvent.IsAllDayEvent; } if(StdEvent.EndDateTime != null){ CustEvent.Start__c=StdEvent.EndDateTime; } if(StdEvent.EndDateTime != null){ CustEvent.End__c=StdEvent.EndDateTime; } if(StdEvent.WhatId != null){ CustEvent.What__c=StdEvent.WhatId; } if(StdEvent.WhoId != null){ CustEvent.Who__c=StdEvent.WhoId; } if(StdEvent.IsPrivate != null){ CustEvent.Private__c=StdEvent.IsPrivate; } if(StdEvent.Priority__c != null){ CustEvent.Priority__c=StdEvent.Priority__c; } if(StdEvent.Location != null){ CustEvent.Location__c=StdEvent.Location; } if(StdEvent.ShowAs != null){ CustEvent.Show_Time_As__c=StdEvent.ShowAs; } return CustEvent; } Public static Event_Object__c insertCustom(Event StdEvent ){ Event_Object__c CustEvent = new Event_Object__c(); if(StdEvent.OwnerId != null){ CustEvent.Assigned_To__c=StdEvent.OwnerId; } if(StdEvent.Subject != null){ CustEvent.Subject__c=StdEvent.Subject; } if(StdEvent.Type != null){ CustEvent.Type__c=StdEvent.Type; } if(StdEvent.StartDateTime != null){ CustEvent.Start__c=StdEvent.StartDateTime; } if(StdEvent.IsAllDayEvent != null){ CustEvent.IsAllDayEvent__c=StdEvent.IsAllDayEvent; } if(StdEvent.EndDateTime != null){ CustEvent.End__c=StdEvent.EndDateTime; } if(StdEvent.Act_Type__c != null){ CustEvent.Reason__c=StdEvent.Act_Type__c; } if(StdEvent.WhatId != null){ CustEvent.What__c=StdEvent.WhatId; } if(StdEvent.WhoId != null){ CustEvent.Who__c=StdEvent.WhoId; } if(StdEvent.IsPrivate != null){ CustEvent.Private__c=StdEvent.IsPrivate; } if(StdEvent.Priority__c != null){ CustEvent.Priority__c=StdEvent.Priority__c; } if(StdEvent.Location != null){ CustEvent.Location__c=StdEvent.Location; } if(StdEvent.ShowAs != null){ CustEvent.Show_Time_As__c=StdEvent.ShowAs; } if(StdEvent.Description != null){ CustEvent.Description__c=StdEvent.Description; } CustEvent.Standard_Event__c = StdEvent.id; CustEvent.name='Custom Event'; return CustEvent; }
Class :::
Rabi,
It might be possible that u have create any unique field and when you are trying to submit it is showing error.
This very tipical to solve this problem like this. If you need help we can discuss this issue
Yes i have a unique field::Standard_Event__c
request you to please help me on this
EventObjectSync: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Class.EventObjectSyncClass.Updatecustom: line 76, column 1 Trigger.EventObjectSync: line 76, column 1
Please confirm if still you are facing this problem.
EventObjectSync: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Class.EventObjectSyncClass.Updatecustom: line 76, column 1 Trigger.EventObjectSync: line 77, column 1
please help me on this...i am struck since yesterday
Or we can share the screen to resolve the issue
We can not access this sandbox out of the organization.
If any input required from my side...please let me know...