1

I am trying to create a Aura component that fires the create new page with the default values. I am calling the Aura Component from the Quick action where I can get the the record ID but how I can get the associated ID of the record in the component

<aura:component implements="lightning:availableForFlowActions,force:hasRecordI">
  <aura:attribute name="recordId" type="Id" />
</aura:component>

Client Side Controller

({
 invoke : function(component, event, helper){
   var CalibrationID =  component.get("v.recordId"); 

   var createRecordEvent = $A.get("e.force:createRecord");

   createRecordEvent.setParams({ 
     "entityApiName": "QA_Review__c", 
     "defaultFieldValues": {
      'QA_Calibration__c' : CalibrationID,
       'Agent__c': xxxxxxxxxxxxxxxxxxxxxxxx,
       'Type__c': "Test",
       'Case__c': xxxxxxxxxxxxxxxxxxxxxxxxxxxx
    } 
  });
  createRecordEvent.fire(); 
 }

})

Where Agent__c and Case__c are related(lookup) records

enter image description here

Since I have the record ID is it possible to get the associated/ related record IDs Agent__c and Case__c that is assocaited with the record ID without making a server side call.

1 Answer 1

0

You will need at least SOME communication with the server, but at least you won't have to write any code yourself.

You can use the aura recordData component (or even the lwc version if you want).

You would write something like this:

<aura:attribute name="obj" type="Object"/>
<aura:attribute name="simpleObj" type="Object"/>
<aura:attribute name="objError" type="String"/>
<force:recordData aura:id="objRecordLoader"
    recordId="{!v.recordId}"
    fields="Agent__c,CaseNumber__c"
    targetRecord="{!v.obj}"
    targetFields="{!v.simpleObj}"
    targetError="{!v.objError}"
    recordUpdated="{!c.handleRecordUpdated}"
/>

As soon as your recordId becomes filled (which I note has a typo in your code at the top - force:hasRecordI is missing the D, then your target fields will be come filled and you can then prefill your desired record.

However, you will need to wait until the record loads, so you would NOT use the invoke method... which is ONLY for lwc components.

When handleRecordUpdated is invoked, you would then fire the createRecordEvent.

eg:

handleRecordUpdated : function(component, event, helper){
   let calibrationID =  component.get("v.recordId"); 
   let createRecordEvent = $A.get("e.force:createRecord");

   createRecordEvent.setParams({ 
     "entityApiName": "QA_Review__c", 
     "defaultFieldValues": {
      'QA_Calibration__c' : calibrationID,
       'Agent__c': component.get("v.simpleObj.Agent__c"),
       'Type__c': "Test",
       'Case__c': component.get("v.simpleObj.CaseNumber__c")
    } 
  });
  createRecordEvent.fire(); 
 }
1
  • Thank you.. how can this be used in the controller ? Commented Apr 11, 2023 at 18:32

You must log in to answer this question.

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