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
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.
I am certified Salesforce Developer with Sales and Service cloud certifications. I am a true believer in #GivingBack principle and a Salesforce enthusiast. I am working as a member of our #SalesforceOhana to learn and help other fellow Trailblazers of the community to grow and learn.
“I’m a true believer in karma. You get what you give, whether it’s bad or good.”
Hi Bro, can you also give the code for “AccountEditController” class it was missing in this post.
Updated the Gist.
Very Nice! Can you share the Test Class(es) for ther Apex code?