1

Currently, sending a Employee enroll input form on a object H_HRBasic__c to the apex class method

CMP

<aura:attribute name="HRB_S" type="H_HRBasic__c" default="{'sobjectType':'H_HRBasic__c',
                                                               'Emp_NM__c':'',
                                                               'Birth_YMD__c':'',
                                                               'Sex_Type__c':'',
                                                               'Email__c':'',
                                                               'Mobile_NO__c':''}"/>
<aura:attribute name="newHRB_S" type="H_HRBasic__c[]"/>
<aura:attribute name="PsID" type="String" />

<lightning:input aura:id="hrbsform" name="Emp_NM__c" value="{!v.HRB_S.Emp_NM__c}" label="Name" required="true" type="String" style="margin-top:10px;" />
<lightning:input  aura:id="hrbsform" value="{!v.PsID}" label="SOCIALID" required="true" style="margin-top:10px;" />
<lightning:input aura:id="hrbsform" type="date" name="Birth_YMD__c" label="Birth date" value="{!v.HRB_S.Birth_YMD__c}" />
<lightning:select aura:id="hrbsform" label="M/F" name="Sex_Type__c" value="{!v.HRB_S.Sex_Type__c}">
                          <option value="">None</option>
                          <option value="Male">Male</option>
                          <option value="Female">Female</option>
 </lightning:select>
<lightning:input aura:id="hrbsform" value="{!v.HRB_S.Email__c}" name="Email__c" label="Email" style="margin-top:10px;" />
<lightning:input  aura:id="hrbsform" value="{!v.HRB_S.Mobile_NO__c}" name="Mobile_NO__c" label="Phone" style="margin-top:10px;" />
<lightning:button  variant="neutral" label="save" onclick="{!c.getsaveIns}" />

Helper

setSaveIns : function(component,event,helper,newhrbs,psid){
    var action = component.get('c.saveIn_S');
    console.log('hrbs : : : : : '+newhrbs);
    console.log('psid : : : : : '+psid);
    action.setParams({

        "HRB_S" : newhrbs,
        "PsID"  : psid
    });

    action.setCallback(this, function(response){
        var result = response.getReturnValue();
        var state = response.getState();
        var toast = $A.get("e.force:showToast");

        if(state == 'SUCCESS') {

            console.log('SUCCES!!!!~'+JSON.stringify(result));

        } else {
            console.log('fail'+JSON.stringify(result));

        }

    });
    $A.enqueueAction(action);
},

APEX

@AuraEnabled
public static void saveIn_S(H_HRBasic__c HRB_S, String PsID){
                // HRB_S =  new H_HRBasic__c;
                system.debug('psid : : : :'+psid);

LINE 135:Null system.debug('HRB_S : : : :'+HRB_S);

    H_AssignBasic__c AssB_S = new H_AssignBasic__c();
    H_RetireBasic__c RB_S = new H_RetireBasic__c();
    H_AttendBasic__c AttB_S = new H_AttendBasic__c();
    H_HolsBasic__c HB_S = new H_HolsBasic__c();
    H_PayBasic__c PB_S = new H_PayBasic__c();
    H_4InsBasic__c Ins4B_S = new H_4InsBasic__c();
    H_YearTaxBasic__c YTB_S = new H_YearTaxBasic__c();
..

ERROR ON DEVELOPER CONSOLE

18:26:33:002 USER_DEBUG [135]|DEBUG|HRB_S : : : :null


But it goes well after I instantiate a custom object H_HRBasic__c constructor on the apex method:

    H_HRBasic__c HRB_S = new H_HRBasic__c ();
    system.debug('psid : : : :'+psid);
    system.debug('HRB_S : : : :'+HRB_S);

Is JSON stringify the problem? How can I solve it?

H_HRBasic__c HRB_S object parameter contains null ** +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ **Controller

    getsaveIns : function(component, event, helper){

    var validhrbs = component.find("hrbsform").reduce(function (validSoFar,inputCmp){
        inputCmp.showHelpMessageIfInvalid();
        return validSoFar && inputCmp.get('v.validity').valid;
    }, true);



    if(validhrbs){
        var hrbs = component.get("v.HRB_S");
        var newhrbs = component.get("v.newHRB_S");
        var item = JSON.parse(JSON.stringify(hrbs));
        newhrbs.push(item);
        component.set("v.HRB_S",newhrbs);
        var psid = component.get("v.PsID");
        console.log('hrbs'+JSON.stringify(newhrbs));
        helper.setSaveIns(component,event,helper,newhrbs,psid);
    }


},
  • Your code does not seem to include any lines which could throw this error. Please edit your post to include a more complete version of your Apex, and include your error's stack trace string, clearly indicating which line is the culprit. – Adrian Larson Sep 21 '18 at 2:22
  • H_HRBasic__c HRB_S object parameter contains null on a apex class... Error is not a problem. i just want to get H_HRBaisc__c HRB_S object parameter on a apex class which is containing input form data but it gives null.... – Jayee Sep 21 '18 at 2:41
  • 1
    You are passing what appears to be an array (H_HRBasic__c[]) to a method that accepts a param of a single H_HRBasic__c object (not array). This is likely what is causing the issue. I will write up a better answer when I get back in 20 minutes. – Caspar Harmer Sep 21 '18 at 2:57
  • Actually, it's not clear what's happening. Can you include your controller method + the output of the console log of the object you are sending to the Apex controller? – Caspar Harmer Sep 21 '18 at 4:04
  • Thanks for comment, [{"sobjectType":"H_HRBasic__c","Emp_NM__c":"Jake","Birth_YMD__c":"","Sex_Type__c":"male","Email__c":"","Mobile_NO__c":""},[{"sobjectType":"H_HRBasic__c","Emp_NM__c":"Jake","Birth_YMD__c":"","Sex_Type__c":"male","Email__c":"","Mobile_NO__c":""}]] H_NewEmployee.js:36 hrbs : : : : : [object Object],[object Object] – Jayee Sep 21 '18 at 4:30
0

Not sure how you are accessing the instance of HRB_S attribute, but below is simplified version of code (as its hard to replicate all of your fields).

Maybe you can use it as baseline to see what you are missing in your code.

Markup

    <aura:component controller="EmployeeFormController">
    <aura:attribute name="HRB_S" type="HRBasic__c" default="{'sobjectType':'HRBasic__c',
                                                               'Employee_Name__c':'',
                                                               'Email__c':''}"/>
<aura:attribute name="PsID" type="String" />

<lightning:input aura:id="hrbsform" name="Employee_Name__c" value="{!v.HRB_S.Employee_Name__c}" label="Name" required="true" type="String" style="margin-top:10px;" />
<lightning:input  aura:id="hrbsform" value="{!v.PsID}" label="SOCIALID" required="true" style="margin-top:10px;" />
<lightning:input aura:id="hrbsform" value="{!v.HRB_S.Email__c}" name="Email__c" label="Email" style="margin-top:10px;" />


<lightning:button  variant="neutral" label="save" onclick="{!c.getsaveIns}" />
</aura:component>

Controller

getsaveIns : function(component, event, helper) {
    //call helper
    helper.setSaveIns(component);
}

Helper

setSaveIns : function(component) {
    var hrbs = component.get("v.HRB_S");
    var psid = component.get("v.PsID");
    console.log('hrbs::' + hrbs.Employee_Name__c);
    console.log('psid::' + psid);

    var action = component.get("c.saveEmployee");
    action.setParams({ 'HRB_S' : hrbs, 'PsID' : psid});
    action.setCallback(this, function(response){
        if(response.getState() === 'SUCCESS'){
            console.log('--SUCCESS--' + response.getReturnValue());
        }
    });
    $A.enqueueAction(action);
}

Apex

@AuraEnabled
public static Id saveEmployee(HRBasic__c HRB_S, string PsID ){
    system.debug('HRBasic__c' + HRB_S);
    system.debug('PsID' + PsID);

    //insert HRBasic__c
    insert HRB_S;
    return HRB_S.id;
}
  • problem was an attribute that instantiated twice in the markup THANKS~! – Jayee Sep 21 '18 at 6:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.