You need to sign in to do that
Don't have an account?

System.NullPointerException: Attempt to de-reference a null object issue in Trigger
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
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
You need to chage this to this..
let me know..
--
Thanks,
Prashant
All Answers
You are not giving the right record type label..
I am assuming your record type Name is
--
Thanks,
Prashant
thanks for response.....
i tried...but no luck, getting same error ...do you think is there any other reasons for this error ? Thanks
have you made record type on contact object?
Because 'idRecType ' not getting an ID on contact object have a name 'IVR_Task_Record'
Please check
Thanks
Nikhil
Send me your record type detail page..then I ca better help you..
There is higer probability that you are not checking the right record type name.
--
Thanks,
Prashant
thanks for your responsne, please find RecordType details.
Requirement is , when ever record created under 'IVR_Journey__c ' , task created under Contact---> Activity history.
You need to chage this to this..
let me know..
--
Thanks,
Prashant
one more help on this ...could you please let me know if you have any idea on this .
As of now, when record created in custom object(IVR_journey_c) , when ever record created under 'IVR_Journey__c ' , tasks created under Contact--->custom IVR Journey BUT not under Activity History.
my requirement is , when ever record created under 'IVR_Journey__c ' , tasks created under Contact--->Activity History .
i already maintained lookup relation ship between IVR_journy_C and Task Activities. But the above code si not working
do you have any idea on this ....?
If you close the task that will show in the ActivityHistory...
--
Thanks,
Prashant