• Nikhil Deshmukh 11
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi all,
my scenario is : When record created in custom object (IVR_object) then Task created under Contact object .
i written below code, but when i try to deploy the code getting below errror 
Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger createTask caused an unexpected exception, contact your administrator: createTask: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.createTask: line 5, column 1

even i  remove line 5 also getting same error , can some one please check below code and pls let me know how to fix this

trigger createTask on IVR_Journey__c (after insert) {
    List<Task> taskToInsertList = new List<Task>();
    List<Contact> contactToUpdateList = new List<Contact>();
   id idRecType = Schema.SObjectType.Contact.getRecordTypeInfosByName().get('IVR_Task_Record').getRecordTypeId();
       for (IVR_Journey__c ivj : trigger.new) {
        Task task = new Task();
        task.Subject = 'IVR Self Service';
        task.WhoId = ivj.Ivr_Journey__c;
        task.Status = 'Completed';
        task.ActivityDate = date.Today();
        task.Authentication_Result__c = ivj.Authentication_Result__c;
        task.Caller_ID__c = ivj.Caller_ID__c;
        task.Contact_Channel_Duration__c = ivj.Contact_Channel_Duration__c;
        task.Contact_Intent__c = ivj.Contact_Intent__c;
        task.Automated_Task_Completed__c = ivj.Automated_Task_Completed__c;
        task.Transfered_To__c = ivj.Transfered_To__c;
        task.Survey_Option__c = ivj.Survey_Option__c;
        task.DNIS__c = ivj.DNIS__c;
        task.Start_Date_Time__c = ivj.Start_Date_Time__c;
        task.End_Date_Time__c = ivj.End_Date_Time__c;
        task.Language_Preference__c = ivj.Language_Preference__c;
        Contact contact = new Contact (Id = ivj.Ivr_Journey__c);
        Task.RecordTypeId = idRecType;
        taskToInsertList.add(task);
        contactToUpdateList.add(contact);
        
    }
    
    if(taskToInsertList.size() > 0)
        insert taskToInsertList;
        
    if(contactToUpdateList.size() > 0)
        update contactToUpdateList;
  
}
please check and let me know why this error coming ............Thanks in advance
  • June 11, 2018
  • Like
  • 0