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
punith narasimhapunith narasimha 

how to use apex:param tag in lightning component

hi,
in vf page we have a tag i.e  apex:param by using this we can pass parameters  from vf page to Apex controller 
now i want to do same scenario  in lightning component  please help me
thank u,
Shubham4462Shubham4462
Hello punith 

u can refer this link https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_actions_call.htm (http:// https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_actions_call.htm)

or either u can check this sample code 

------------- Component File-----
<aura:component controller="TestingController">
 <lightning:button label="Call server" onclick="{!c.callingServerMethod }"/>    
</aura:component>

-----------Client Side Controller File-------

({
    callingServerMethod : function(component, event, helper) {
        var action = component.get("c.serverMethod");
        action.setParams({
            "setParams" : "Hello calling server Method",
        });
        
        action.setCallback(this,function(response){
            
            var retValueFromServer = response.getReturnValue();
            alert(retValueFromServer);
    });
        
        $A.enqueueAction(action);
    }
})


---------------Server Side Controller File---------


public class TestingController {

    
    @AuraEnabled
    public static String serverMethod(String setParams){
        return setParams;
    }
}


I think this will help you

Thanks....
Khan AnasKhan Anas (Salesforce Developers) 
Hi Punith,

Greetings to you!

You can use event.getSource() in the client-side controller to get the button/checkbox component that was clicked. 

In the client-side controller, you can use one of the following methods to find out which button was clicked.
  • event.getSource().getLocalId() returns the aura:id of the clicked button.
  • event.getSource().get("v.value") returns the name of the clicked button.

Below is the sample code which will give you a clear idea about it.

Component:
<aura:component controller="ButtonToControllerC"
                implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="mydata" type="List"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.doinit}" />
    
    <div class="slds-section slds-is-open">
        <h3 class="slds-section__title slds-theme_shade">
            <span class="slds-truncate slds-p-horizontal_small" title="Section Title">Account Details Table - 1</span>
        </h3>
        <br/>
        <table class="slds-table slds-table--bordered slds-table--striped slds-table--cell-buffer slds-table--fixed-layout">
            <thead>
                <tr class="slds-text-heading--label">
                    <th scope="col"><div class="slds-truncate" title="Account Name">Account Name</div></th>
                    <th scope="col"><div class="slds-truncate" title="Phone">Phone</div></th>
                    <th scope="col"><div class="slds-truncate" title="Show" aura:id="selectAll"></div></th>
                </tr>
            </thead>
            <tbody>
                <aura:iteration items="{!v.mydata}" var="row">
                    <tr>
                        <th scope="row"><div class="slds-truncate" title="{!row.Name}">{!row.Name}</div></th>
                        <td><div class="slds-truncate" title="{!row.Phone}">{!row.Phone}</div></td>
                        <td>
                            <div>                           
                                <lightning:button label="SHOW"
                                                  value="{!row}"
                                                  iconName="utility:new"
                                                  iconPosition="left"
                                                  variant="brand"
                                                  onclick="{!c.show}"
                                                  />
                            </div>
                        </td>
                    </tr>
                </aura:iteration>
            </tbody>
        </table>
    </div>
</aura:component>

Controller:
({
    doinit : function(component, event, helper) {
		var action = component.get('c.fetchRecords');
        action.setCallback(this, function(response){
            var state = response.getState();
            if(state === "SUCCESS"){
                var allValues = response.getReturnValue();
                console.log("allValues--->>> " + allValues);
                component.set('v.mydata', allValues);
            }
            else if(state === "ERROR") {
                var errors = response.getError();
                if(errors){
                    if(errors[0] && errors[0].message){
                        console.log("Error Message: " + errors[0].message);
                    }
                }
                else{
                    console.log("Unknown Error");
                }
            }
        });
        $A.enqueueAction(action);
	},
    
    show : function(component, event, helper) {
        var rowRecord = event.getSource().get('v.value');
        alert('Buttom Pressed -> ' + JSON.stringify(rowRecord));
        console.log('rowRecord--->>> ' + JSON.stringify(rowRecord));
        
    }
})

Apex:
public class ButtonToControllerC {

    @AuraEnabled
    public static List<Account> fetchRecords() {
        return [SELECT Id, Name, Phone FROM Account];
    }
}

Please refer to below links which might help you further.

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_cb_which_button_pressed.htm

https://developer.salesforce.com/forums/?id=906F0000000kAn0IAE

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas