2

I have a lightning component in which i want to display help text for the fields. I can use for sure. But is there any way to get the help text from backend. I mean when we create the field in the org we provide some help text. Can that help text be called in the custom component?

  • You can use the field describe calls to get the help text for fields. However there's no out of the box way in which the help text can be shown directly in the components. You will have to use a custom wrapper to wrap the help text along with other field information. – Saket Joshi Mar 11 at 7:32
2

Out of the box is not there, but there is a workaround.
You can hold the loading of help text until you get the help text response from server.

Lets say there are fields called Test_Field1__c and Test_Field2__c on Test_Object__c.

In Apex:

@AuraEnabled
public static Map<String, String> getHelpText() {
    String helpText1 = Test_Object__c.Test_Field1__c.getDescribe().getInlineHelpText();
    String helpText2 = Test_Object__c.Test_Field2__c.getDescribe().getInlineHelpText();
    return Map<String, String> { 'Test_Field1__c'=>helpText1, 'Test_Field2__c'=>helpText2 };
}

And in lightning component

<aura:attribute name="helpText1" type="String" default="" />
<aura:attribute name="helpText2" type="String" default="" /> 
<aura:attribute name="initDone" type="Boolean" default="false" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:if isTrue="{!v.initDone}">
    <lightning:helptext content="{!v.helpText1}" />
    <!-- field 1 -->
    <lightning:helptext content="{!v.helpText2}" />
    <!-- field 2 -->
</aura:if>

In js controller

doInit: function(component) {
   //call apex
    var action = component.get('c.getHelpText'); 

    action.setCallback(this, function(response){
        var resp = response.getReturnValue();
        component.set("v.helpText1", resp.Test_Field1__c);
        component.set("v.helpText2", resp.Test_Field2__c);
        component.set("v.initDone", true);
    });
    $A.enqueueAction(action);
}
  • Hi @Aditya thanks for the reply. this is what i was looking for! – Smruti Ranjan Biswal Mar 11 at 9:31
  • @SmrutiRanjanBiswal glad it helped, you can mark the answer accepted as well so other also can take the reference from here :-) – Aditya Vijay Mar 11 at 9:40
  • yeah sure. Can u also help me with how to get the 'Guidance for Success of Sales Path to the Custom Component or to Apex' – Smruti Ranjan Biswal Mar 11 at 10:47
  • @SmrutiRanjanBiswal that is a part of metadata developer.salesforce.com/docs/atlas.en-us.api_meta.meta/… you need to use Metadata API in order to get this to apex which is a bit complex to use. lightning:picklistPath is there to create the path in component, but it doesn't help with guidance of success or fields. Not sure if something else is there! – Aditya Vijay Mar 11 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.