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
Abdul PatelAbdul Patel 

Server side controller returning blank records

Hi,

I have server side controller which shows the records are fetched properly in the debug logs however, when this is fetched in the lightning compononent, the component shows blanks records.

 
Best Answer chosen by Abdul Patel
Abdul PatelAbdul Patel
Thank you Chandrika for your help . I was able to fix the issue by adding the @AuraEnabled for the variables in my inner class.

All Answers

Abdul PatelAbdul Patel
This is my server side controller - 

/**
 * Created by AU0004ZF on 11/21/2019.
 */

global class AccountDashboardController {

    /*public class tableData{

    }*/
    global class tableRow {
        global String segment;
        global Integer sumOfQuantity;
        global Integer asp;
        global Decimal netAmount;
        //public Map<String, AccountDashboardController.tableData> dataMap;
        global tableRow(String seg,Integer quan, Integer asp, Decimal netAmt) {
            this.segment = seg;
            this.sumOfQuantity = quan;
            this.asp = asp;
            this.netAmount = netAmt;
        }
    }

    @AuraEnabled
    global static List<AccountDashboardController.tableRow> getTableData(Id accountId) {
        List<AccountDashboardController.tableRow> tableRows = new List<AccountDashboardController.tableRow>();
        AggregateResult[] groupedResults = [SELECT Segment__c, SUM(Quantity__c) sumQuan,AVG(ASP_Amount_Base_Report__c) avgASP,SUM(Net_Amount_Base_Report__c) sumAmount FROM Sales_Revenue__c WHERE Account__c =: accountId GROUP BY ROLLUP(Segment__c)];
        for (AggregateResult ar : groupedResults)  {
            Decimal quan = (Decimal)ar.get('sumQuan');
            Decimal avgASPDecimal = (Decimal)ar.get('avgASP');
            /*AccountDashboardController.tableRow row = new AccountDashboardController.tableRow();
            row.segment = (String)ar.get('Segment__c');
            Decimal quan = (Decimal)ar.get('sumQuan');
            row.sumOfQuantity = quan.intValue();

            row.asp = avgASPDecimal.intValue();
            row.netAmount = (Decimal) ar.get('sumAmount');
            System.debug('row>>' + row);
            tableRows.add(row);*/
            //System.debug('Average amount' + ar.get('expr0'));
            AccountDashboardController.tableRow row = new AccountDashboardController.tableRow((String)ar.get('Segment__c'),
                    quan.intValue(),
                    avgASPDecimal.intValue(),
                    (Decimal) ar.get('sumAmount'));
            tableRows.add(row);
        }
        System.debug('tableRows>>'+tableRows);
        return tableRows;
    }
}

The lighting component  - 
<!--
 - Created by AU0004ZF on 11/21/2019.
 -->

<aura:component description="AccountDashboard" controller="AccountDashboardController" access="global" extends="c:Base"
                implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId,force:lightningQuickAction">
    <!-- attributes -->
    <aura:attribute name="data" type="AccountDashboardController.tableRow[]"/>
    <aura:attribute name="columns" type="List"/>

    <!-- handlers-->
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>


    <!-- the container element determine the height of the datatable -->
    <div style="height: 300px">
        <lightning:datatable
                keyField="segment"
                data="{!v.data}"
                columns="{!v.columns}"
                hideCheckboxColumn="true"/>
    </div>
</aura:component>

And the lighting controller -
 
/**
 * Created by AU0004ZF on 11/21/2019.
 */
({
    doInit: function(component, event, helper){

        console.log("accountId>>", component.get("v.recordId"));
        var accountId = component.get("v.recordId");
        /*var recordId = component.get("v.recordId");
        if(recordId.startsWith('001')){
            accountId = recordId;
        }*/

        component.set('v.columns', [
            {label: 'Segments', fieldName: 'segment', type: 'text'},
            {label: 'Quantity', fieldName: 'sumOfQuantity', type: 'number'},
            {label: 'ASP', fieldName: 'asp', type: 'number'},
            {label: 'Net Amount(Base)', fieldName: 'netAmount', type: 'number'}
            ]);
        helper.exec(
            component,
            helper,
            "c.getTableData",
            function(response){

                var state = response.getState();

                if(state === "SUCCESS") {

                    var returnedRows = response.getReturnValue();
                    console.log("returnedRows>>", response.getReturnValue());
                    component.set("v.data",returnedRows);
                }
            },
            {accountId:accountId}
        );
    }
})

 
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi abdul,
Can you please post your helper code here.
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi abdul,
I tried came code in org .It is working for me.
May be  the issue is you are  not using $A.enqueueAction(action); after invoking server side controller method.

Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.

Thanks and Regards

 
Abdul PatelAbdul Patel
Thank you Chandrika for your help . I was able to fix the issue by adding the @AuraEnabled for the variables in my inner class.
This was selected as the best answer