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

Passing other field values from lightning component to apex


We have built a lighting com to display the Contact and Opportunity data in hierarchy structure. We are able to pass the current records Id but how do we pass its related fields to apex. Like we need to pass the account Id from contact  to apex controller.

Deepali KulshresthaDeepali Kulshrestha
Hi Desai,
You can do this by using setParam 

setParam (string keyObject value)
Sets a single parameter for the Action.

Get the id of account that you want to record and set Id in an attribute, and in controller set the id of account in setParam and query the related records in apex controller.

In Controller:

Get the Id of account from attribute like this.
  let taskId = c.get('v.parentId');

Pass it into the parameter

let sample = c.get('c.MethodNameInApexController');
        "currentId" : taskId 

Apex Controller:

    public static List<Opportunities > MethodName(String currentId) {

        List<Opportunities > opportunitieslist= new List<Opportunities >();
        opportunitieslist = [select Id, Name  from Opportunities where AccountId=: currentId];
        System.debug('opportunitieslist --->' + opportunitieslist );
        return opportunitieslist ;

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

 Thanks and Regards,
 Deepali Kulshrestha
Hi Deepali,

How do i get the account id value in component ?