Skip to main content
added 365 characters in body
Source Link
salesforce-sas
  • 24.5k
  • 5
  • 44
  • 79

layoutType="FULL" will fetch the default layout assigned to that user. From LDS Docs, when you specify fields (included/excluded from default page layout), they are also loaded.

The issue (I would rather say the bug in documentation):

  1. fields attribute will not trigger the reload of record. So, it is better to use conditional rendering. Reason: When record is initially loaded, the fields is not yet set by doInit method and when the fields are set, the recordData will not reload the record. Ofcourse you can use reloadRecord() but its not required as you need extra fields. So, if you use conditional rendering (When fields!=null), the recordData will load ONLY after the fields are set .
  2. Although documentation shows fields attribute as String, it is actually a List .

Below is the sample working code with respect to above points:

COMPONENT:

<aura:attribute name="recordFields" type="List" default="[]"  />
<aura:attribute name="accountRecord" type="Object"/>
<aura:attribute name="recordLoadError" type="String"/>

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

<div class="slds-theme_default slds-box">
    <aura:if isTrue="{!not(empty(v.recordFields))}">
        <force:recordData aura:id="recordLoader"
                          recordId="00128000009j45uAAA"
                          layoutType="FULL"
                          fields="{!v.recordFields}"
                          targetFields="{!v.accountRecord}"
                          targetError="{!v.recordLoadError}"
                          />
        
        Name - {!v.accountRecord.Name}, Active - {!v.accountRecord.Active__c}
    </aura:if>
</div>

CONTROLLER JS:

init : function(component, event, helper){
    component.set("v.recordFields",['Name','Type','Phone','Active__c','Description']);
},

Note that List has to be set on fields.

layoutType="FULL" will fetch the default layout assigned to that user. From LDS Docs, when you specify fields (included/excluded from default page layout), they are also loaded.

The issue (I would rather say the bug in documentation):

  1. fields attribute will not trigger the reload of record. So, it is better to use conditional rendering .
  2. Although documentation shows fields attribute as String, it is actually a List .

Below is the sample working code with respect to above points:

COMPONENT:

<aura:attribute name="recordFields" type="List" default="[]"  />
<aura:attribute name="accountRecord" type="Object"/>
<aura:attribute name="recordLoadError" type="String"/>

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

<div class="slds-theme_default slds-box">
    <aura:if isTrue="{!not(empty(v.recordFields))}">
        <force:recordData aura:id="recordLoader"
                          recordId="00128000009j45uAAA"
                          layoutType="FULL"
                          fields="{!v.recordFields}"
                          targetFields="{!v.accountRecord}"
                          targetError="{!v.recordLoadError}"
                          />
        
        Name - {!v.accountRecord.Name}, Active - {!v.accountRecord.Active__c}
    </aura:if>
</div>

CONTROLLER JS:

init : function(component, event, helper){
    component.set("v.recordFields",['Name','Type','Phone','Active__c','Description']);
},

Note that List has to be set on fields.

layoutType="FULL" will fetch the default layout assigned to that user. From LDS Docs, when you specify fields (included/excluded from default page layout), they are also loaded.

The issue (I would rather say the bug in documentation):

  1. fields attribute will not trigger the reload of record. So, it is better to use conditional rendering. Reason: When record is initially loaded, the fields is not yet set by doInit method and when the fields are set, the recordData will not reload the record. Ofcourse you can use reloadRecord() but its not required as you need extra fields. So, if you use conditional rendering (When fields!=null), the recordData will load ONLY after the fields are set .
  2. Although documentation shows fields attribute as String, it is actually a List .

Below is the sample working code with respect to above points:

COMPONENT:

<aura:attribute name="recordFields" type="List" default="[]"  />
<aura:attribute name="accountRecord" type="Object"/>
<aura:attribute name="recordLoadError" type="String"/>

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

<div class="slds-theme_default slds-box">
    <aura:if isTrue="{!not(empty(v.recordFields))}">
        <force:recordData aura:id="recordLoader"
                          recordId="00128000009j45uAAA"
                          layoutType="FULL"
                          fields="{!v.recordFields}"
                          targetFields="{!v.accountRecord}"
                          targetError="{!v.recordLoadError}"
                          />
        
        Name - {!v.accountRecord.Name}, Active - {!v.accountRecord.Active__c}
    </aura:if>
</div>

CONTROLLER JS:

init : function(component, event, helper){
    component.set("v.recordFields",['Name','Type','Phone','Active__c','Description']);
},

Note that List has to be set on fields.

Source Link
salesforce-sas
  • 24.5k
  • 5
  • 44
  • 79

layoutType="FULL" will fetch the default layout assigned to that user. From LDS Docs, when you specify fields (included/excluded from default page layout), they are also loaded.

The issue (I would rather say the bug in documentation):

  1. fields attribute will not trigger the reload of record. So, it is better to use conditional rendering .
  2. Although documentation shows fields attribute as String, it is actually a List .

Below is the sample working code with respect to above points:

COMPONENT:

<aura:attribute name="recordFields" type="List" default="[]"  />
<aura:attribute name="accountRecord" type="Object"/>
<aura:attribute name="recordLoadError" type="String"/>

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

<div class="slds-theme_default slds-box">
    <aura:if isTrue="{!not(empty(v.recordFields))}">
        <force:recordData aura:id="recordLoader"
                          recordId="00128000009j45uAAA"
                          layoutType="FULL"
                          fields="{!v.recordFields}"
                          targetFields="{!v.accountRecord}"
                          targetError="{!v.recordLoadError}"
                          />
        
        Name - {!v.accountRecord.Name}, Active - {!v.accountRecord.Active__c}
    </aura:if>
</div>

CONTROLLER JS:

init : function(component, event, helper){
    component.set("v.recordFields",['Name','Type','Phone','Active__c','Description']);
},

Note that List has to be set on fields.