function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tamilselvan chinnasamyTamilselvan chinnasamy 

salesforce Button label

How to change the name of the button label as record changes? dynamically... ? If type is prospect, then button label should change to prospect. How to do that?
Best Answer chosen by Tamilselvan chinnasamy
Tamilselvan chinnasamyTamilselvan chinnasamy
Thank you suraj and Abinav for the time !
****component:**** 
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId"  controller ="DynamicButton"  access="global"  >
    <aura:attribute name="buttonName" type="string" default = "Test"/>
    <aura:handler name="init" value="{!this}" action="{!c.doretrive}" />
        <div class="slds-box slds-theme_default">
            <h1> Account type </h1>
            <lightning:button  label= "{!v.buttonName}"   /> 
        </div>
</aura:component>
and 
*****controller:********
({
  doretrive : function(component, event, helper) {
        
        var action = component.get("c.dispbutton");
        action.setParams({'recordId':component.get('v.recordId')});
     action.setCallback(this,function(data){           
            component.set('v.buttomnName',data.getReturnValue())
          });   
    $A.enqueueAction(action); 
  }   
})
return the value in the disbutton method .

thankyou
 

All Answers

AbhinavAbhinav (Salesforce Developers) 
Hi Tamilselvan,

Have you checked this link for similar use case?

https://salesforce.stackexchange.com/questions/38521/how-to-change-label-on-custom-button-based-on-value-in-the-record-being-displaye

https://www.forcetalks.com/salesforce-topic/how-to-change-label-on-custom-button-based-on-value-in-the-record-being-displayed/

If it helps mark it as best answer.

Thanks!
Suraj Tripathi 47Suraj Tripathi 47
Hi Tamilselvan,
Greetings!

You can change the label of the lightning button.
<lightning:button variant="brand" label="{!buttonLabel}" title="Brand action" onclick="{! c.handleClick }" />
change buttonLabel value which you want.

If you find your Solution then mark this as the best answer. 

Thank you!

Regards,
Suraj Tripathi
Tamilselvan chinnasamyTamilselvan chinnasamy
Thank you suraj and Abinav for the time !
****component:**** 
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId"  controller ="DynamicButton"  access="global"  >
    <aura:attribute name="buttonName" type="string" default = "Test"/>
    <aura:handler name="init" value="{!this}" action="{!c.doretrive}" />
        <div class="slds-box slds-theme_default">
            <h1> Account type </h1>
            <lightning:button  label= "{!v.buttonName}"   /> 
        </div>
</aura:component>
and 
*****controller:********
({
  doretrive : function(component, event, helper) {
        
        var action = component.get("c.dispbutton");
        action.setParams({'recordId':component.get('v.recordId')});
     action.setCallback(this,function(data){           
            component.set('v.buttomnName',data.getReturnValue())
          });   
    $A.enqueueAction(action); 
  }   
})
return the value in the disbutton method .

thankyou
 
This was selected as the best answer