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
aks0011aks0011 

Lightning Server Side ?

Hi,

I'm facing an issue while passing a sobject in parameters from a form helper js to apex controller's aura enabled method that works to save that form's data in DB. At the Client side It works well or I don't know but at Apex controller there is an error is being occurred as [VARIABLE_ASSIGNMENT [6]|ex|"common.apex.runtime.impl.ExecutionException: Attempt to de-reference a null object"|0x3a7b04fe] so if anyone has the solution then please let me know. 

thanks in advance :)
Adrian  GawryszewskiAdrian Gawryszewski
Please share your code. It basically says your sending null value across, so no object. At that stage I would say if you really want to send object from Aura to Apex serialize it beforehand and than pass it through. 
aks0011aks0011
Hi Adrian Gawryszewski,

Thanks for the reply and then I would say sorry because I was busy with some other things so did'nt get chance to respond you back.
Let me share some of my code with you :

Demo.cmp
<aura:component controller="DemoPageController" implements="force:appHostable">
    <aura:attribute name="accounts" type="account"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <div class="slds">
        <fieldset class="slds-form--compound">
            <div class="form-element__group">
                <div class="slds-form-element__row">
                    <div class="slds-form-element slds-size--1-of-2">
                        <label class="slds-form-element__label" for="input-01">Name</label>
                        <ui:inputText class="slds-input" value="{!v.accounts.Name}"/>
                    </div>
                </div>
            </div>
        </fieldset>
        <div class="slds-form-element__row slds-p-top--small">
            <input type="button" value="Save" class="slds-button slds-button--brand"
                   onclick="{!c.submit}"/>
        </div>
    </div>
</aura:component>

DemoController.js

({
    doInit : function(component, event, helper) {
        helper.getAccounts(component);
    },
    
    submit : function(component, event, helper) {
        var newAccRec = component.get('v.accounts');
        console.log(newAccRec);
        helper.save(component, newAccRec);
    },
})

DemoHelper.js

({
    getAccounts: function(component) {
        var action = component.get("c.getAccounts");
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (component.isValid() && state === "SUCCESS") {
                component.set("v.accounts", response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
    },
    
    save : function(component, newAccRec) {
        var action = component.get("c.saveRecord");
        action.setParams({
            "accountRecord": newAccRec
        });
        action.setCallback(this, function(response) {
            var isSaved = response.getReturnValue();
            if (isSaved) {
                console.log('record saved '+isSaved+' and execution ends...');
            }
            else
                console.log('record saved false and execution ends...');
        });
        $A.enqueueAction(action);
    },
})

DemoPageController.apxc

public class DemoPageController {
    @AuraEnabled
    public static Account getAccounts() {
        return new account(name = 'test light account');
    }
    
    @AuraEnabled
    public static boolean saveRecord(Account accountRecord) {
        system.debug('@apex save...' + accountRecord);
        return true;
    }
}

This above mentioned code is supposed to be worked to save a new account record in sf database.

I'm using this in SF classic as given below -:

DemoPage.vfp

<apex:page sidebar="false">
    <apex:stylesheet value="{!URLFOR($Resource.SLDS0121, 'assets/styles/salesforce-lightning-design-system-vf.css')}" />
    <apex:includeLightning />
    <div id="containerLight">
        <div id="Lightning"/>
    </div>
    
    <script>
        $Lightning.use("c:DemoApp", function(){
            $Lightning.createComponent("c:Demo",{},"Lightning",function(cmp){
                
            });
        });
    </script>
</apex:page>


Please look at this and let me know if you have any solution for this. thanks in advane :)