How to get the RecordType/Id Name of Account Object based on AccountId and Assign the Record Type Name to Lightning Component :







Here are the steps on how to get the RecordType/Id Name of Account Object based on AccountId and Assign the Record Type Name to Lightning Component:

  1. Create a Lightning Component.
  2. In the component controller, add the following code:

public with sharing class MyComponentController {

Code snippet
@AuraEnabled
public static String getRecordTypeName(Id accountId) {
    SObject record = [SELECT Id, RecordTypeId, RecordType.Name FROM Account WHERE Id = :accountId];
    return record.RecordTypeId == null ? null : record.RecordType.Name;
}

}

  1. In the component markup, add the following code:
Code snippet
<aura:attribute name="accountId" type="Id" />
<aura:attribute name="recordTypeName" type="String" />

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

<div>
    Account ID: {!v.accountId}
    Record Type Name: {!v.recordTypeName}
</div>
  1. In the component controller's init method, add the following code:

public void init(ComponentEvent event) {
    // Get the account ID from the component attribute.
    Id accountId = event.getParam("accountId");
    // Get the record type name.
    String recordTypeName = MyComponentController.getRecordTypeName(accountId);
    // Set the record type name component attribute.
    set("v.recordTypeName", recordTypeName);
}
  1. Save the component and deploy it to your org.
  2. In a Lightning App, add the component to a page.
  3. Enter an account ID in the component input field.
  4. Click the Submit button.
  5. The record type name will be displayed in the component output field.




Comments

Popular posts from this blog

Mapping of Flows in Salesforce