If you are looking for an alternative of {!$ObjectType.Account.fields.Name.Label} then this post is the perfect destination for you. In this post, I am going to demonstrate the easiest way of showing field labels dynamically instead of hard-coding them.
lightning:input and ui:input doesn’t have a capability to get the label from the field itself like force:inputField and using this solution you can achieve it easily.
Problem: How can I access field labels dynamically just like we can do in a Visualforce page using the {!$ObjectType.Account.fields.Name.Label}?
Solution: Create an attribute in your lightning component which has got the value from the following utility method.
Component which is using field label and picklist options dynamically.
So, you can reference the label with following syntax
{!v.ObjectType.sObjectName.FieldApiName.label}
sObjectName – Account
FieldApiName – Name
https://gist.github.com/sfcure/4a3aba223989c5cd842f969cf81267a8
In getDescribedObjects method you can pass a list of objects and can reference them in the lightning component. You can add more properties like required and readOnly.
By Naveen Sharma
July 1, 2018Hi Bro, can you also give the code for “AccountEditController” class it was missing in this post.
By Naveen Sharma
July 1, 2018Updated the Gist.
By Naveen Sharma
January 25, 2019Very Nice! Can you share the Test Class(es) for ther Apex code?