I have a Custom Object as TUC object .When i create a record in TUC obj , it should automatically create a record in Event and Task.But the trigger written is not getting fired .Any help is very much appreciated.
Here is the Code :
trigger CreateEvent on TUC__c(after insert){
List<Event> eventList = new List<Event>();
for(TUC__c tucObj : Trigger.new){
Event event = new Event();
event.whatid = tucObj.Account_Related__c;
event.Subject = tucObj.subject__c;
event.OwnerId = tucObj.CreatedById;
event.StartDateTime = tucObj.Start_Date__c;
event.EndDateTime=tucObj.End_Date__c;
eventList.add(event);
}
if(eventList.size()>0 && eventlist!==null){
insert eventList;
}
}
if
condition second part intoeventList != null
and tryif (eventList.size()>0 && eventlist !=null)
will not handle nulls. Ifeventlist
is ever null (and it never will be in your case) then you will get a NPE error oneventList.size()
. The check should beif (eventlist !=null && eventList.size() > 0)