You need to sign in to do that
Don't have an account?
lxch
Aura Component "argument can not be null"
Hi all, if anyone spot what is the cause of in the following code error?
debug log tells me that is "argument can not be null."
and it seems it null pointer exception issue in the loop of for (Billing__c due : dueBillings) part, but not sure what can fix this.
The logic is Apex Controller is called by controller.js fetchDueBalance method, pass the return value to the controller.js, then set component dueBalance (Decimal) in the component.
Apex Controller
Component
debug log tells me that is "argument can not be null."
and it seems it null pointer exception issue in the loop of for (Billing__c due : dueBillings) part, but not sure what can fix this.
The logic is Apex Controller is called by controller.js fetchDueBalance method, pass the return value to the controller.js, then set component dueBalance (Decimal) in the component.
Apex Controller
@AuraEnabled public static Decimal fetchDueBalance(Id recordId) { // check which object started the apex class Decimal dueBalance; String sObjName = recordId.getSObjectType().getDescribe().getName(); List<Billing__c> dueBillings = new List<Billing__c>(); System.debug('dueBlalance: initial point: ' + dueBalance); //passed if (sObjName == 'Billing__c') { Billing__c bl = [ SELECT Id, Case__c FROM Billing__c WHERE Id =:recordId LIMIT 1 ]; dueBillings = [ SELECT Id, Due_Balance__c FROM Billing__c WHERE Case__c = :bl.Case__c AND Due_Balance__c !=0 AND User_Due_Date__c < :Date.today() ORDER BY User_Due_Date__c ASC ]; System.debug('dueBlalance: list search: ' + dueBalance); // passed if (dueBillings != null){ System.debug('dueBlalance: nullcheck: ' + dueBalance); // passed dueBalance = 0; for (Billing__c due: dueBillings) { dueBalance += due.Due_Balance__c; System.debug('dueBlalance: loop point: ' + dueBalance); /passed } } } return dueBalance; }It passes to the final debug log, but not returning the dueBalance value (Decimal) to the component via controller.
Component
<aura:component controller="BillingCheckController" implements="force:hasRecordId,force:appHostable,flexipage:availableForAllPageTypes"> <aura:handler name="init" value="{!this}" action="{!c.doInit}"/> <aura:attribute name="recordId" type="Id" /> <aura:attribute name="dueBalance" type="Decimal" /> <aura:attribute name="billings" type="Billing__c[]" description="store accounts with there child contacts"/> <h1><lightning:formattedNumber value="{!v.dueBalance}"></lightning:formattedNumber></h1>Controller.js
({ doInit: function(component, event, helper) { //call apex class method var recordId = component.get("v.recordId"); var action = component.get('c.fetchBillings'); action.setParams({recordId :recordId}); action.setCallback(this, function(response) { var state = response.getState(); if (state === "SUCCESS") { component.set('v.billings', response.getReturnValue()); } }); $A.enqueueAction(action); /* action1 for the sumup number of the overdue billings */ var recordId = component.get("v.recordId"); var action = component.get('c.fetchDueBalance'); action.setParams({recordId :recordId}); action.setCallback(this, function(response) { //store state of response var state = response.getState(); if (state === "SUCCESS") { component.set('v.dueBalance', response.getReturnValue()); } }); $A.enqueueAction(action); }, })Help me sleep...
You cannot add a null value to any variable so please change your below code:
Code that needs to be changed: Should be changed to:
Let me know if still there is an issue.
Thanks,
Abhishek Bansal.
All Answers
As the error states it is a null pointer exception can you try checking the value being returned?
Thanks.
First one is to get the list of object and susscessully returnedValues (JSON.stringified), and Chorme console shows it returned. But the second one is not appearing in the Chrome console (not JSON.strigified) dueBalance is the second one, a sing decimal value I'm expecting to get returned. I wonder if I runs 2 getReturnValue for the different methods (fetchBillings, fetchDueBalance) in the same Class...
I appreciate if any hint for the potential solution for this. Thanks!
You cannot add a null value to any variable so please change your below code:
Code that needs to be changed: Should be changed to:
Let me know if still there is an issue.
Thanks,
Abhishek Bansal.