You need to sign in to do that
Don't have an account?
uday uday chavan
null point exception error
Getting this Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger WorkOrderTrigger caused an unexpected exception, contact your administrator: WorkOrderTrigger: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Class.WorkOrderTriggerHelper.CreateWorkOrderItem: line 648, column 1
public static void CreateWorkOrderItem(List<Work_Order__c> workOrder){
list<Work_Order_Item__c> listWOI = new list<Work_Order_Item__c>();
for(Work_Order__c woItem:workOrder){
String[] s = woItem.Service_Type__c.split(';');
if(woItem.Status__c =='Completed' && s.contains('Waste Export') ){
this is 648 line woItem.Account__r.Terminal__c = true;
Work_Order_Item__c newWOI = new Work_Order_Item__c();
newWOI.Work_Order__c = woItem.Id;
newWOI.Quantity__c = woItem.Total_Ordered_Quantity__c;
newWOI.Received_Quantity__c = woItem.Total_Delivered_Quantity__c;
newWOI.Unit_Price__c = woItem.Price__c;
newWOI.Description__c = woItem.Notes__c;
listWOI.add(newWOI);
}
}
Insert listWOI;
}
after insert trigger i am using
i am creating new record for work order item when condition are met also i am updating account related object terminal checkbox to true when condition are met i got this error
Review all error messages below to correct your data.
Apex trigger WorkOrderTrigger caused an unexpected exception, contact your administrator: WorkOrderTrigger: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Class.WorkOrderTriggerHelper.CreateWorkOrderItem: line 648, column 1
public static void CreateWorkOrderItem(List<Work_Order__c> workOrder){
list<Work_Order_Item__c> listWOI = new list<Work_Order_Item__c>();
for(Work_Order__c woItem:workOrder){
String[] s = woItem.Service_Type__c.split(';');
if(woItem.Status__c =='Completed' && s.contains('Waste Export') ){
this is 648 line woItem.Account__r.Terminal__c = true;
Work_Order_Item__c newWOI = new Work_Order_Item__c();
newWOI.Work_Order__c = woItem.Id;
newWOI.Quantity__c = woItem.Total_Ordered_Quantity__c;
newWOI.Received_Quantity__c = woItem.Total_Delivered_Quantity__c;
newWOI.Unit_Price__c = woItem.Price__c;
newWOI.Description__c = woItem.Notes__c;
listWOI.add(newWOI);
}
}
Insert listWOI;
}
after insert trigger i am using
i am creating new record for work order item when condition are met also i am updating account related object terminal checkbox to true when condition are met i got this error
try following code. before using below code make sure that when you are passing trigger.new from trigger to this method CreateWorkOrderItem then you have to pass Terminal__c field because Terminal__c is a relation's field and trigger never give any relation's referance field. so in trigger you have to query this field.
Note - 2 : you never update any relation directly. you have to query of that object and then you have to update. let me know if it helps you and marking it as best answer.
Thank you
All Answers
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Please follow the below code:- Please mark it as Best Answer if it helps you.
Thanks & Regards
Suraj Tripathi
try following code. before using below code make sure that when you are passing trigger.new from trigger to this method CreateWorkOrderItem then you have to pass Terminal__c field because Terminal__c is a relation's field and trigger never give any relation's referance field. so in trigger you have to query this field.
Note - 2 : you never update any relation directly. you have to query of that object and then you have to update. let me know if it helps you and marking it as best answer.
Thank you
also i have question this will work on update trigger
yes, You are right it must be Account__c. It had happend by mistake but when you got solved your answer then must mark it as best answer.
your one best answer give us motivation to helping others.
Thank you