I'm getting this error:

System.NullPointerException: Attempt to de-reference a null object

when I'm trying to pass child records to new record creation(order_LIne_item__c).

Here I have nested Query and I'm passing inner query(child) values to for loop for creating a new record in order_LIne_item__c.

for(Quote_line_item__c qlis : fixOrder.Quote_Line_Items__r){
            ORLI= new order_LIne_item__c();

           if (qlis.Name != null){
           if (qlis.Description__c!= null){
           if (qlis.Client_P_N__c!= null){
          if (ORLI!= null){
             ORINlist.add(ORLI);//addding into the LIST


Why am I getting this error?


You need to declare ORINlist variable and assign with List<order_LIne_item__c>.

So, initially and out of for loop, do this

List<order_LIne_item__c> ORINlist = new List<order_LIne_item__c>();
  • How can I assign like that I want to pass values to order_Line_item__c, & create a new record in order line items – VINOD Jul 24 '18 at 9:30
  • my bad, updated the line – Santanu Boral Jul 24 '18 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.