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

System.NullPointerException: Argument 1 cannot be null
I have created a apex controller in that I calculated
List<PManagement__c PM=[select Rep__c,Revenue___c,Quantity___c,Month_Starting__c,Month_Ending__c from PManagement__c where id=:scon.getId()]; } public pageReference UpdatePerformance(){ if(!PM.IsEmpty()){ PManagement__c PMD= PM[0]; list<sales__c> BS=[select SRep__c,Total_Products__c,Total_Sale_Val__c from SMB_Sales__c where sale_date__c >=:PMD.Month_Starting__c and sale_date__c <=:PMD.Month_Ending__c AND SRep__c=:PMD.Rep__c ];
if(SMBS.size()!=0){
for(Sales__c BS1:BS){ TotalRev += BS1.Total_sale_Val__c; // I think problem is here TotalRev is incremented with null value.. TotalTar += BS1.Total_Products__c; } PMD.Revenue__c=TotalRev; PMD.Quantity__c=TotalTar; Update PMD; return null; }
Now I am writing test case for above controller
ApexPages.StandardController stdcon=new ApexPages.StandardController(PM); RevTarCon Con= new RevTarCon(stdcon); Con.UpdatePerformance(); // This generates error }
I Got System.NullPointerException: Argument 1 cannot be null , error in test class
How I can I solve this problem.. please help me ?
for(Sales__c BS1:BS){
TotalRev += BS1.Total_sale_Val__c;
// I think problem is here TotalRev is incremented with null value.. TotalTar += BS1.Total_Products__c;
)
TotalTar and TotalRev must both be initialized to zero in the constructor as already suggested and ...
All Answers
can you please post the test class code
This is my test class
Hi,
Try initializing in constructor.
TotalTar = 0; before you increment
Regards,
Subham
TotalTar and TotalRev must both be initialized to zero in the constructor as already suggested and ...
Thank you for your response....
I followed your suggestions there is no error but..... in test case assertion failed due to not updating of Revenue__c,Quantity__c.
I have noticed that in debug log above valules are initalized with zeros. How to get success with assertions,.. my test case is avaible in previous post of this problem....
Your testmethod is inserting SM_Sales__c SObjects but your controller method is reading SMB_Sales__c objects
As an aside, these issues are readily resolvable by using system.debug statements in your controller so you can see variable values