I have to pull the Metadata.Layout of an object from apex and basically re-create page layouts in aura. My plan was to use the Metadata.Layout and just iterate over the sections/columns/fields.

In Apex, I have debug statements that show me and the correct Layout is not null and is being properly queried/assigned. However, in aura, I can't seem to iterate over the sections, and I have some test statements set up, and it looks like the Layout section list is coming back as empty. Not sure why this is happening since it is being set correctly, and clearly isn't null on the back end. If anyone has any suggestions, I would greatly appreciate it.

.cmp file

    <aura:attribute name="lineLayout" type="Metadata.Layout"/>
    <aura:attribute name="lineLayoutSections" type="Object[]"/>
    <aura:attribute name="recordTypeId" type="String"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <lightning:recordEditForm aura:id="recordEditForm"
        <lightning:messages />
        <aura:iteration items="{!v.lineLayout.layoutSections}" var="section">
            <div class="slds-section slds-is-open" aura:id="{!section.label}">
                <!--section header-->
                <h3 class="slds-section__title">
                    <button aria-controls="fruitsList" class="slds-button slds-section__title-action">
                        <span onclick="{!c.toggleSection}" data-auraId="fruitsSection">
                            <lightning:icon iconName="utility:switch"
                                            class="slds-section__title-action-icon slds-button__icon_left"
                                            alternativeText="button icon" 
                        <span class="slds-truncate" title="{!section.label}">{!section.label}</span>
                <!--section body-->
                <div class="slds-section__content" id="fruitsList">
                    <aura:iteration items="{!section.layoutColumns}" var="column">
                        <aura:iteration items="{!column.layoutItems}" var="item">
                        <lightning:inputField fieldName="{!item.field}" />
        <lightning:button class="slds-m-top_small" type="submit" label="Save" />


        var action = component.get("c.getLayout");
        action.setParams({ recordTypeId : component.get("v.recordTypeId")});
        action.setCallback(this, function(response) {
            var result = response.getReturnValue();


public class CustomLineFormController {

    //public Line__c line {get; set;}                 
    //public Metadata.Layout lineLayout {get; private set;} 
    public static Metadata.Layout getLayout(String recordTypeId) {
        Metadata.Layout lineLayout;
            List<Metadata.Metadata> components = Metadata.Operations.retrieve(
                new String[]{'Line__c-Non-Referencing AP-Non-Fed: ARC Internal'}
            lineLayout = (Metadata.Layout) components.get(0);
        }catch(Exception e){
            System.debug('Exception: ' + e.getMessage());
        System.debug('test:' + lineLayout.layoutSections);
        return lineLayout;

  • Have you evaluated using the UI API (likely in an LWC)? That's what it is intended to do and is more suited to the purpose than Apex Metadata API.
    – David Reed
    Dec 4, 2020 at 3:31
  • Hi David, that's something I can consider, thanks. I had to make a quick turn around on this and I decided to use aura since I was more familiar with aura. I also didn't quite see why the above wouldn't work... Dec 4, 2020 at 14:13


You must log in to answer this question.

Browse other questions tagged .