1

Component.set is throwing an error when attempting to set an array of sObjects to a named attribute.

Markup

<aura:component controller="QuoteLineAuraController" implements="flexipage:availableForAllPageTypes,force:hasRecordId">

    <!-- Event Handlers -->
    <aura:handler name="init" value="{!this}" action="{!c.initAction}" />

    <!-- Attributes -->
    <aura:attribute name="recordId" type="Id"/> 
    <aura:attribute name="masterContracts" type="MasterContract__c[]"/>

</aura:component>

Javascript Controller

({
    initAction : function(component, event, helper) {
        helper.getMasterContracts(component);
    }
})

Javascript Helper

({
    getMasterContracts : function(component){

        var apexMethodCall = component.get("c.getMCs");

        apexMethodCall.setCallback(component, function(apexMethodResult){
            component.set("v.masterContracts", apexMethodResult.getReturnValue());
        });

        $A.enqueueAction(apexMethodCall);
    }
})

Apex Class

public class QuoteLineAuraController {

    @AuraEnabled
    public static MasterContract__c[] getMCs(){
        return [select Id, Name from MasterContract__c limit 10];
    }
}
2
  • Try changing the attribute type to Object[] Jun 17, 2017 at 5:10
  • You might be using this object collection without iteration tag.
    – brahma
    Jun 17, 2017 at 6:28

0

Browse other questions tagged .