I would like to set a lookup id value for an Aura attribute, but it doesn't work unless i hardcode it. Instead I need to retrieve it from the lookup on the current recordId.

How is this possible to do? From the controller? The value is store in a lookup Child__c on the recordId of the record page where i run the component.

        default="[{'fieldName':'Parent__c', 'operator':'=', 'value': 'a557S000001UJE1QAO' }]"

1 Answer 1


Hard coded value is what works for default values in aura attributes, for dynamic values - it has to be set in controller.

Kindly try

<aura:component implements="force:hasRecordId" controller="ControllerClass">
<aura:attribute name="recordId" type="String" />
    default="[{'fieldName':'Parent__c', 'operator':'=', 'value': '' }]"

    doInit : function(component, event, helper) {
    //'fetchRecordValues' be the apex method in ControllerClass that gets current recordId as input and returns the record with Child__c field value
    var action = component.get("c.fetchRecordValues");
            "recordId": component.get('v.recordId')
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
    //get the returned record and store in a variable, which can then be used to get value of 'Child__c' field
                var storeResponse = response.getReturnValue();
               // set current Child__c information on default value
               component.set("v.myFilters.value" , storeResponse.Child__c );

For reference, kindly have a look at this thread - https://developer.salesforce.com/forums/?id=9060G0000005PbXQAU

  • 1
    Please don't leave link-only answers. They can be broken over time (hint: foreshadowing).
    – sfdcfox
    Aug 22, 2022 at 14:25
  • 1
    sure thanks sfdcfox, will edit accordingly!
    – JPM
    Aug 22, 2022 at 14:40
  • i tried with component.set("v.Child__r.Id" ,lookupId ); and then in the cmp : <aura:attribute name="myFilters" type="B25__Resource__c" default="[{'fieldName':'Parent__c', 'operator':'=', 'value': 'lookupId' }]" /> But it doesn't work
    – Brian23Gt
    Aug 22, 2022 at 14:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .