I want to create a page that display a list of object. I get the list of the objects from a table. then i pass it to javascript controller to display it in the lightning component. My code is below :
Controller Apex
@AuraEnabled
public static List<BatchToBeExecuted> getBatchs (){
List<BatchToBeExecuted> arrayItems = new BatchToBeExecuted[]{};
List<SICo_BatchTobeExecuted__mdt> listBatchs = [SELECT Id,DeveloperName,
BatchSize__c FROM SICo_BatchTobeExecuted__mdt ];
if(!listBatchs.isEmpty()){
for( SICo_BatchTobeExecuted__mdt aBatch : listBatchs){
arrayItems.add(newBatchToBeExecuted(aBatch.DeveloperName,aBatch.BatchSize__c));
}
}
System.debug('return value'+arrayItems);
return arrayItems ;
}
Controller Javascript
init : function(component, event, helper) {
let action = component.get("c.getBatchs");
action.setCallback(this,function(response){
const state = response.getState();
console.log('state='+state);
if(state==="SUCCESS"){
var batchs = response.getReturnValue();
var result = [{batchSize:2000, name:"SICo_DeleteArchive_Batch"}];
component.set("v.aBatchToBeExecuted", result);
console.log('return result='+JSON.stringify(batchs)) ;
}
The console.log of JSON.stringify(return value) show a blank table
<table>
<aura:iteration items="{!v.aBatchToBeExecuted}" var="batchToBeExecuted">
{!batchToBeExecuted.name}
{!batchToBeExecuted.batchSize}
</aura:iteration>
<lightning:button onclick="{!c.getString}" label="Update"/>
</table>