Ad Code

How to pass parameters from client-side controller to server-side apex class in salesforce lightning framework


Hello trailblazer, as we know that lightning framework supports two controllers one is client-side controller which gives the capability to render the data in the browser and the second one is server-side controller which is apex class which helps in data manipulation at the service side. In this article, we are going to learn how to pass the parameters from the lightning component to the server-side apex class. 


Step1


In the lightning component bundle, navigate to controller or helper function where you have a logic to call apex and refer the below code to make the changes as per your requirement.

Make sure to initialize the apex controller method to the action variable as shown in the above screenshot and Use action.setparams method to set the input parameters. In this case, we are passing two parameters, one is contact object on contacttoInsert variable and account Id in accountId variable.


Step 2:

In the previous step, we set parameters from the calling function. It’s time to edit the apex class to receive the parameters at the server-side. Refer the screenshot. 



Make sure to add @AuraEnabled annotation for the method that you are calling and the parameters that are defined in the lightning component controller or helper method should be similar to the input parameters that are mentioned in the apex class.

In this article, we learned passing parameters from the client to the server. In case if you see any issues in implementing this put it in the comments section below. 


ALSO READ

Salesforce lightning interview questions - Part 1

Salesforce lightning interview questions - Part 2 

Post a Comment

0 Comments