function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
steve456steve456 

Null pointer Exception

I am getting a null pointer exception.Do not know what mistake am doing 

 

 

CODE

 

 

trigger UpdateTransactRevenue on Order_Entry__c (before insert, before update) {
  Set<Id> productIdList=new Set<Id>();
  Set<Id> orderIdList=new Set<Id>();

  
  //process all records if they are new
  if(Trigger.isInsert)
  {
    for(Order_Entry__c oe:Trigger.new)
    {
      if(oe.Product__c!=null && oe.Order_Number__c!=null)
      {
        productIdList.add(oe.Product__c);
        orderIdList.add(oe.Order_Number__c);
      }
    }
  }
  
  if(Trigger.isUpdate)
  {
    for(Order_Entry__c oe:Trigger.new)
    {
         if(oe.Order_Number__c!=null && oe.Product__c!=null && oe.Product__c!=Trigger.oldMap.get(oe.Id).Product__c)
         {
         
           productIdList.add(oe.Product__c);
           orderIdList.add(oe.Order_Number__c);

           
         }
    }
  }
  
  
  
  if(productIdList.size()>0) 
  {
    //query for employee records
    Map<Id,Product_2020__c> productMap=new map<Id,Product_2020__c>([Select Id,Invoice_Rate_Blend__c , Invoice_Rate_Event__c from Product_2020__c where Id in:productIdList]);
    Map<Id,Order_2020__c>   orderMap = new Map<Id,Order_2020__c>([Select Id , Name , Transact_Kiosk_Category__c from Order_2020__c where Id in:orderIdList]);
    
    String recordtypeid=[Select Id from RecordType where Name='2020RK-VZ' and SobjectType='Order_Entry__c'].Id;
       
    if(orderMap!=null && orderMap.size()>0){
        for(Order_Entry__c oe:Trigger.new)
        {
         if(oe.RecordTypeId==recordtypeid){
           
           
               
               if(orderMap.get(oe.Order_Number__c)!=null && orderMap.get(oe.Order_Number__c).Transact_Kiosk_Category__c=='Event' && productMap!=null && productMap.get(oe.Product__c)!=null && productMap.size()>0 && productMap.get(oe.Product__c).Invoice_Rate_Event__c!=null)
               {
                   oe.Transact_Revenue__c=productMap.get(oe.Product__c).Invoice_Rate_Event__c * oe.Quantity__c; 
               }
               else if(orderMap.get(oe.Order_Number__c)!=null && orderMap.get(oe.Order_Number__c).Transact_Kiosk_Category__c!='Event'&& productMap!=null && productMap.get(oe.Product__c)!=null && productMap.size()>0 && productMap.get(oe.Product__c).Invoice_Rate_Blend__c!=null){
               
                   oe.Transact_Revenue__c=productMap.get(oe.Product__c).Invoice_Rate_Blend__c * oe.Quantity__c; 
               }
           
          }       
        } 
    }       
  } 

 

 

 

 

ERROR

 

 

caused by: System.NullPointerException: Argument 1 cannot be null

Trigger.UpdateTransactRevenue: line 57, column 1(highlighted is line 57)

 

 

 

 

Can any body help me please

Naidu PothiniNaidu Pothini

Did you try looking in debug log?

 

can you check whats the value in productMap.get(oe.Product__c) 

 

 

steve456steve456

I am not gtting this error through the UI .Its through a third pary app and its tuf to catch all the logs

goabhigogoabhigo

Since you are checking for - productMap.get(oe.Product__c).Invoice_Rate_Blend__c!=null, it may not be null, but if you also check oe.Quantity__c != null, it might help. My only guess here is Quantity might be null, but I am not sure whether it is mandatory. As mentioned by Naidu, why don't you put a system.debug() for these values inside else if(), and check the values. Once you have put check it the logs under Administration Setup - Monitoring - Debug Logs.