+ Start a Discussion

Argument cannot be null in method


Created a method below which is calling reCalRslrDiscSalPrc am passing aruments or parameters in this method  on of the arument is null due to which am getting error please suggest me how to modifiy or handle such argument null exception

public PageReference calcOnReDistSalPrcchange () {
         Decimal glistprice;
         Decimal chkresller = 0;
        for(OptyLineWrapper linew : lineWrapr) {        
            OpportunityLineItem backuplne = backUpLines.get(lineW.line.id);
          //  if ( lineW.line.Reseller_discount_rate__c <> null ) 
          //  {
                if ( lineW.line.PricebookEntry.name != 'COTERM' )
                  glistprice = lineW.line.listprice;
                  glistprice = lineW.line.CoTerm_List_Price__c;                 
                 system.debug('glistprice = '+ glistprice);
                 system.debug('lineW.line.PricebookEntry.Product2.Category__c = '+ lineW.line.PricebookEntry.Product2.Category__c);
                 system.debug('lineW.line.Reseller_discount_rate__c = '+ lineW.line.Reseller_discount_rate__c);
                   lineW.line.UnitPrice = reCalRslrDiscSalPrc(glistprice,lineW.line.PricebookEntry.Product2.Category__c,Decimal.Valueof(lineW.line.Reseller_discount_rate__c);  );
           // }
        return null;

  Below method is called in above method passing parameter. 
/* calculate disti discount */  
    public static Decimal reCalRslrDisc(Decimal listprice,String productcat, Decimal reslrdistdiscount){
        Boolean isService = false;
        system.debug('listprice = ' + listprice);
        system.debug('productcat = ' + productcat);
        system.debug('reslrdistdiscount = ' + reslrdistdiscount);
        if ( productcat=='C' || productcat=='E'|| productcat=='D'|| productcat=='H'|| productcat=='I'|| productcat=='J' )
            isService = true;
        if ( reslrdistdiscount <> null && isService == true)
            NSP_Margin_Schedule__c NMS =  [ Select Distributor_Discount__c From NSP_Margin_Schedule__c 
                                           where  Reseller_Discount__c = :reslrdistdiscount and 
                                           Service__c = :isService and 
                                           createddate < 2015-01-17T00:00:00-08:00 ];
            return NMS.Distributor_Discount__c;
            return 0;

Dileep KumarDileep Kumar

Hi Sudhir,

You can solve this problem in two ways:

1.> You need to give some value of  'Reseller_discount_rate__c' field.For this you will open your record and give some value and save.

2.>open object ->Open Reseller_discount_rate__c field and Required field should be unchecked.
Because you are getting error due to validation on it.

If it will useful .please mark it as a best answer.

If you will face any problem let me know.



Hi Dileep, 

  Thanks for your responce this is not a required field so cannot make it required. Alternative way the methods what am doing is a caculation which will update other fields since Reseller_discount_rate__c is stored as null it is accepting null value during call of method can you suggest me how to default it to 0 if is null