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
Board salesforceBoard salesforce 

System.NullPointerException: Argument cannot be null. in test class

Hi techi's,

Please solve this issue

constructor;
try
        {
            orderDetails = (OrderItem)controller.getRecord();
            system.debug('orderdetails'+orderdetails);
            orderDetails = [select id,Stage__c,OrderItemNumber,Quantity from OrderItem where id=:orderDetails.Id];
            Production = new Production_Stage__c();
            Production.Order_Product__c = orderDetails.id;
            system.debug('inputstatus is '+inputstatus);
            productionStageMap=new Map<String,Decimal>();
            productionStageSeqMap=new Map<Decimal,String>();
            
            Map<String,ProductionStage__c> tempMap = ProductionStage__c.getAll();
            
            for(String stageName : tempMap.KeySet())
            {
                if(tempMap.get(stageName)!=null)
                {
                    ProductionStage__c tempObj =tempMap.get(stageName);
                    productionStageMap.put(tempObj.Name,tempObj.Sequence_Number__c);
                    productionStageSeqMap.put(tempObj.Sequence_Number__c,tempObj.Name);
                }
            }
            system.debug('productionStageMap ' + productionStageMap);
            system.debug('productionStageSeqMap ' + productionStageSeqMap.keySet());
        }
        catch(exception ex)
        {
            system.debug('mesg '+ ex.getLineNumber() +'  no '+ex.getMessage());
        }
Method :
 public PageReference saveAndnew()
    {
        
        system.debug('The entered production object is ' + Production );
        system.debug('The input stage is ' + inputstatus);   
        system.debug('The production stages are ' + productionStageMap );
        
        PageReference pr;
        
        decimal Quantity = Production.Quantity__c;
        Production_Stage__c previousProductionstages = new Production_Stage__c();
        decimal completedquantity=0;
        decimal DateQty;
        decimal stageqty=0;
        decimal qty=0;
        decimal quan;
        decimal tqty;
        List<decimal> ldec;
        set<string> stageName=new set<string>();
        List<Production_Stage__c>  ProdMap;
        List<Production_Stage__c> stagelist = [select id,Quantity__c,Stage__c from Production_Stage__c where Stage__c=:inputstatus and Order_Product__c =:orderDetails.id];//stagelist here am getting null value&&inputstatus is null
        system.debug('stagelist is'+stagelist);
        
        for(Production_Stage__c ps : stagelist)
        {
            system.debug('Production Qty is'+Production.Quantity__c);
            qty= qty+ps.Quantity__c;
            //stageqty= Production.Quantity__c+quan;
            //completedquantity=stageqty+Production.Quantity__c;
        }
        
        quan = qty+Production.Quantity__c;

Mytest class:
 Production_Stage__c pstage2=new Production_Stage__c();
        pstage2.Date_In__c=system.today();
        pstage2.Date_Out__c=date.newInstance(2015,12,20);
        pstage2.Order_Product__c=oi.id;
        pstage2.Stage__c ='Schedule';
        pstage2.Sequence_Number__c=1;
        pstage2.Quantity__c=5;
        insert pstage2;
        system.debug('SSSSSSS'+pstage2);
        //insertion of custom settings
      
         
        ProductionStage__c ps1=new ProductionStage__c();
        ps1.Name=pstage.Stage__c;
        ps1.Sequence_Number__c=1;
        insert ps1;
       
        system.debug('ProductionStageps1'+ps1);
        
        PageReference pageRef = Page.ProductionProcessVf;
        test.setCurrentPage(pageRef);
        ApexPages.StandardController con = new ApexPages.StandardController(oi);
        system.debug('CCCCCCCCCon'+con);
        
         
        Production_Controller proc= new Production_Controller(con);
        system.debug('CCCCCCCCCon'+proc);
        
      
        proc.inputstatus='PreProcessing';
        proc.getstatusOptions();
        proc.saveAndnew();//Here getting Null pointer Exception 
        proc.cancel();
can any one help?
AnupPrakash_AlgoworksAnupPrakash_Algoworks
https://developer.salesforce.com/forums/?id=906F00000008y7QIAQ
Vishal Negandhi 16Vishal Negandhi 16
So when you call the SaveAndNew method in your test class, I see you have debug statements. 
Can you confirm what part of the method is throwing this exception? 
I am keen to know what do you get for this debug?
The entered production object is ....
Board salesforceBoard salesforce
----->here an getting null value  please see the comments error i have got
 system.debug('inputstatus is '+inputstatus);
and error at 
     List<Production_Stage__c> stagelist = [select id,Quantity__c,Stage__c from Production_Stage__c where Stage__c=:inputstatus and Order_Product__c =:orderDetails.id];//stagelist here am getting null value&&inputstatus is null
        system.debug('stagelist is'+stagelist);
        
        for(Production_Stage__c ps : stagelist)
        {
            system.debug('Production Qty is'+Production.Quantity__c);
            qty= qty+ps.Quantity__c;
            //stageqty= Production.Quantity__c+quan;
            //completedquantity=stageqty+Production.Quantity__c;
        }
        
        quan = qty+Production.Quantity__c;
here am gettng proc.saveAndnew();//Here getting Null pointer Exception  
Arun Deepan LJArun Deepan LJ
Hi,
Try initializing the all string values in the constructor such as inputstatus  = ' ' ; And make sure, with the help of debug, that it contains some value before performing the query
Board salesforceBoard salesforce
Thanks for the Replu Arun,
   proc.inputstatus='PreProcessing';
        proc.getstatusOptions();
        proc.saveAndnew();//Here getting Null pointer Exception 
        proc.cancel();
As i mentioned above in debug it still null value
Arun Deepan LJArun Deepan LJ
May I know, From where the ​inputstatus value is assigned. 
Board salesforceBoard salesforce
inputstatus :its a getter setter value 
<apex:selectList id="pickField" size="1" value="{!inputstatus}" label="Stages"> <apex:selectOptions value="{!statusOptions}"> </apex:selectOptions> </apex:selectList>
Arun Deepan LJArun Deepan LJ
Is the Inputstatus is public and having get set properties
Board salesforceBoard salesforce
 public string inputstatus{get;set;}

Yes
 
Board salesforceBoard salesforce
Guys Stuck with Argument cannot be null can any one help me?