While exploring Lightning Data Service, I came across another option to load record without apex/soql in Lightning components using lightning:recordViewForm tag, which works in conjunction with lightning:outputField to display specific fields of the record provided by recordId attribute.

There is another attribute of this component, objectApiName and the documentation only gives following information about the attribute

The API name of the object. (this attribute is required)

Now, the fun part is, I just have to put this attribute in the component, no matter what value I provide against this attribute, the component is rendered successfully on the basis of the recordId. Few examples given below

Examples-Component rendered successfully

  1. <lightning:recordViewForm recordId="0066F00000kkQVfQAM" objectApiName="Opportunity">

  2. <lightning:recordViewForm recordId="0066F00000kkQVfQAM" objectApiName="">

  3. <lightning:recordViewForm recordId="0066F00000kkQVfQAM" objectApiName="garbage">

Only case where the component is not rendered, when the objectApiName is not provided, which offcourse is required

<lightning:recordViewForm recordId="0066F00000kkQVfQAM" >

What is the purpose of objectApiName attribute if it has not impact on the outcome?


Purely speculation, but my guesses are:

  • that there is a base component that lightning:recordViewForm extends that supports the "new" case where there is no Id and so the type needs to be known
  • having the type up front is an optimisation compared with working out the type from the Id
  • as the component evolved, the implementation did require it in early versions but not in later versions but the attribute has been left required
  • Sorry @Keith C for late acceptance. I was looking for an official response, I even tweeted this to Salesforce Devs but nothing came up. So, until an official response comes up, I am accepting yours as the best. :) – Mahmood Jan 5 '18 at 20:57
  • @Mahmood No problem and no need to accept it: just some guesses based on little... – Keith C Jan 5 '18 at 20:59
  • No, I must say they are pretty good guesses. :) So it is, so far, the best answer. – Mahmood Jan 5 '18 at 21:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.