function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Phuc 2Phuc 2 

Get object name dynamically in Aura component

Hello 
How can I get the object name within an Aura Component based on the record.
Instead of having this while on the Account record:
<lightning:card>
          <lightning:messages />
          <table>
            <th>
              <lightning:recordForm
                aura:id="accountRecordForm"
                recordId="{!v.recordId}"
                objectApiName="Account"
                columns="2"
                mode="readonly"
              />

I want to be able to have this no matter what objetc record I am on:
<lightning:card>
          <lightning:messages />
          <table>
            <th>
              <lightning:recordForm
                aura:id="RecordForm"
                recordId="{!v.recordId}"
                objectApiName="Object API name based on record"
                columns="2"
                mode="readonly"
              />

Thank you,
P
SwethaSwetha (Salesforce Developers) 
HI Phuc,
You could create an attribute like parent /ParentType and use the ParentType as input for the objectApiName.

See this related post from past
https://salesforce.stackexchange.com/questions/216748/is-it-possible-to-use-lightningrecordeditform-dynamically-on-different-object-t


If this information helps, please mark the answer as best. Thank you