You need to sign in to do that
Don't have an account?

Passing other field values from lightning component to apex
Hi,
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.
Regards,
Desai
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.
Regards,
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');
sample.setParams({
"currentId" : taskId
});
Apex Controller:
@AuraEnabled
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
How do i get the account id value in component ?
Regards,
Desai