[SalesForce] Cannot load data using force:recordData from the component

I'm struggling to get fetch data from my component using Lightning Data Service.
My component is linked to a custom action to create a new record for a custom object.
Below is the error i get when the page load :

Display error after clicking on the NEW record button

—————myComponent.cmp———————–

<aura:component implements="lightning:actionOverride,flexipage:availableForRecordHome,force:hasRecordId" access="global" >

<!--components attributes-->
<aura:attribute name="customObject" type="Object"/>
<aura:attribute name="newCustomObject" type="Object"/>
<aura:attribute name="simpleCustomObject" type="Object"/>
<aura:attribute name="customObjectError" type="String"/>
<force:recordData aura:id="customObjectRecordLoader"
    LayoutType="FULL"
    fields=""
    recordId="{!v.recordId}" 
    targetRecord="{!v.newCustomObject}"
    targetFields="{!v.simpleCustomObject}"
    targetError="{!v.customObjectError}"
    mode="EDIT"
/>
    <aura:if isTrue="{!not(empty(v.newCustomObjectError))}">
        <div class="recordError">
            <ui:message title="Error" severity="error" closable="true">
                {!v.newCustomObjectError}
            </ui:message>
        </div>
    </aura:if>
</aura:component>

——————-myComponentController.js————————————–

({
 doInit: function(component, event, helper) {
  component.find("customObjectRecordLoader").getNewRecord(
   "Custom_Object__c", // objectApiName
   null, // recordTypeId
   false, // skip cache?
     $A.getCallback(function() {
       var rec = component.get("v.newCustomObject");
       var error = component.get("v.newCustomObjectError");
      if(error || (rec === null)) {
        console.log("Error initializing record template: " + error);
      }
      else {
        console.log("Record template initialized: " + rec.sobjectType);
      }
    })
  );
 }
})

I really don't understand what's wrong with my code so thank a lot for your help!

Best Answer

Case sensitivity for layoutType.

FYI, you probably shouldn't include a null fields attribute if you have layoutType specified.

The fields attribute should be specified in conjunction with layoutType when you want fields that are absolutely needed, even if they were removed from the page layout

<force:recordData aura:id="customObjectRecordLoader"
    layoutType="FULL"
    recordId="{!v.recordId}" 
    targetRecord="{!v.newCustomObject}"
    targetFields="{!v.simpleCustomObject}"
    targetError="{!v.customObjectError}"
    mode="EDIT"
/>
Related Topic