- Get link
- X
- Other Apps
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:
- Create a Lightning Component.
- 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;
}
}
- 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>
- 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);
}
- Save the component and deploy it to your org.
- In a Lightning App, add the component to a page.
- Enter an account ID in the component input field.
- Click the Submit button.
- The record type name will be displayed in the component output field.
- Get link
- X
- Other Apps
Comments
Post a Comment