You need to sign in to do that
Don't have an account?
prady
System.DmlException: Delete failed. First exception CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY
Hi,
I am having a scenario where i am deleting a record in object A, it should delete int ObjectB too. so i have the triggers written to delete the records.
When i write the test class i get the following error
System.DmlException: Delete failed. First exception on row 0 with id 00UM0000001ItxKMAS; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, delete_app: execution of AfterDelete caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.delete_app: line 8, column 1: []
Here are the triggers
trigger delete_app on Event (after delete) { List<Id> ev = new List<Id>(); List<Event> eventlist = new List<Event>(); List<Appointment__c> appoint = new List<Appointment__c>(); if (CApp_static.firstRunAppointment==false) { CApp_static.firstRunAppointment=true; for(Event e:Trigger.new) { ev.add(e.id); } appoint=[select id from Appointment__c where eventid__c in :ev]; if (appoint.size()>0) { delete appoint; } } }
trigger delete_event on Appointment__c (after delete) { List<Id> ev = new List<Id>(); List<Event> eventlist = new List<Event>(); List<Appointment__c> appoint = new List<Appointment__c>(); if (CApp_static.firstRunAppointment==false) { CApp_static.firstRunAppointment=true; for(Appointment__c e:Trigger.new) { ev.add(e.id); } eventlist=[select id from Event where appointment_ID__c in :ev]; if(eventlist.size()>0) { delete eventlist; } } }
Here is the test class
public with sharing class TestCreateEvent_Create_App { static testMethod void CreateEvent_Create_App() { Contact a = new Contact(); a.FirstName = 'TestFirst Name'; a.LastName='Test Last Name'; a.MailingStreet='Test billing Street'; a.MailingCity='Test Billing City'; a.MailingState='Test Billing State'; a.MailingCountry='Test Billing country'; a.MailingPostalCode ='Test PostCode'; insert a; String strstartdatetime='2011-12-25 10:00:00'; String strenddatetime='2011-12-25 10:00:00'; Event e= new Event(); e.WhoId=a.id; e.subject ='Test Event' ; e.StartDateTime=datetime.valueof(strstartdatetime); e.EndDateTime=datetime.valueof(strenddatetime); e.Appointment_Type__c='Call'; e.Status__c='Tentative'; e.Create_Appointment__c=true; insert e; strstartdatetime='2011-12-28 10:00:00'; strenddatetime='2011-12-28 10:00:00'; Appointment__c ap= new Appointment__c(); ap.subject__c= 'Test App'; ap.client__c=a.id; ap.name='Test Name'; ap.StartDateTime__c=datetime.valueof(strstartdatetime); ap.EndDateTime__c=datetime.valueof(strenddatetime); ap.Appointment_Type__c='Call'; ap.Status__c='Confirmed'; insert ap; List <event> even= new List<event>(); even=[select id,Appointment_Type__c,subject,StartDateTime,EndDateTime from Event where id=:e.id]; even[0].subject='Test Event update' ; update even; even=[select id,Appointment_Type__c,subject,StartDateTime,EndDateTime from Event where id=:e.id]; if (even.size()>0) { delete even; } List <Appointment__c> apList= new List<Appointment__c>(); apList=[select id,name,subject__c,Appointment_Type__c,EndDateTime__c,StartDateTime__c from Appointment__c where id=:ap.id]; apList[0].Subject__c='Test App update'; update apList; delete apList; } }
Any ideas where i am going wrong?
Can you share the "CApp_static" class, it seems that the variable "firstRunAppointment" was not initialized.