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
GÜNES AdminGÜNES Admin 

How to pass custom object recordID to lightning button to perform action?

Dear everyone,

I am new to Apex/Lightning development so please use simple language in your answer :)

I have a custom object called Change.
I have a lightning button called "Cancel Change", placed in a Lightning Component (aura).
At the moment, the button is just displaying a dummy text "You clicked on me"...
The true purpose of this button is to:
- get the Change recordId (record where the button was pressed)
- update the picklist value of field "Stage" to "Canceled".
- display a success message
- do not navigate away, remain on the same Change record

So, I have the CMP file that defines the visual aspects of the Buttons:

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<div align="right">
    <lightning:buttonGroup>
        <lightning:helptext content="Use these buttons as Workflow Actions"/>
        <p><lightning:button variant="success" label="Progress Workflow" onclick="{!c.handleClick}"/></p>
        <p><lightning:button variant="destructive" label="Cancel Change" onclick="{!c.handleClick}"/></p>
    </lightning:buttonGroup>
</div>
</aura:component>

And there is the JS file which would normally define the behavior:

({
    handleClick : function(component, event, helper) {
    var selectedButtonLabel = event.getSource().get("v.label");
    alert("You clicked on: " + selectedButtonLabel);
    
    }
})

My difficulty is:
- How do I pass the recordID of the Change record to the code
- How do I update the field inside the record when Cancel is pressed?

Do I need to write an Apex container to start with?

Please provide guidance, thank you in advance!!