0

I have a Quick Action button on the Highlight Panel of Case page that launches a Lightning Aura Comp (QA: Detail page button with URL). Through pageReference, I was able to access the parent CaseId. Now that I have CaseId, how can I fetch few field values of this Case record without Apex controller class?

I've tried:

CMP

<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:attribute name="CaseId" type="String" />
<aura:attribute name="caseRecord" type="Object"/>
<aura:attribute name="recordError" type="String"/>
<force:recordData aura:id="recordLoader"
  fields="Sample__c"
  recordId="{!v.CaseId}"
  targetFields="{!v.caseRecord}"
  targetError="{!v.recordError}"
  recordUpdated="{!c.handleRecordUpdated}"
  />

JS

handleRecordUpdated: function(component, event, helper){
   console.log('Inside Handle method'); //Not getting logged. 
    var eventParams = event.getParams();
    if(eventParams.changeType === "LOADED") {
        console.log("Case loaded with:" + component.get("v.caseRecord"));
    }
}

I couldn't get any log for the above debug statement. So, not sure if the function handleRecordUpdated even gets fired. I do have implementation for creating a subtab within doInit.

Update: To give more context, I have a Case landing page where we have a Highlight panel. Here, we are implementing a QuickAction button of display type: Detail Page Button with URL as: /lightning/cmp/c__MySampleAuraComponent. This Aura comp contains doInit where we are using workspaceAPI to open a subtab for a custom object's standard record creation form. So, to prepopulate few fields from Case object, I was trying to fetch parent case field values. I know I could go down the Apex controller path, but decided to give it a try without it to minimize code maintenance.

I have tried Lightning Message Services to publish the necessary fields, but no luck with QuickAction implementation on the highlights panel.

Update 11/22: I am setting the CaseId value within my doInit function and I can verify the data in my console. But not sure why it is not getting passed to force:recordData as I don't see any log from handleRecordUpdated.

4
  • Do you get a message in recordError? That would be hint as to why handleRecordUpdated is not called. If the fields and record Id are set correctly, everything should work.
    – sfdcfox
    Commented Nov 19, 2021 at 20:23
  • @sfdcfox I couldn't get any log for recordError variable. I could see v.CaseId value set from my doInit function. As a matter of fact, I couldn't get any log from the function: handleRecordUpdated. Commented Nov 19, 2021 at 22:27
  • @AustinEvans could this be a case-sensitive issue ? check if CaseId is referenced everywhere with uppercase "C"
    – Shamina
    Commented Nov 24, 2021 at 13:27
  • @AustinEvans also crosscheck the docs if parameter is named correctly with c__ when using pageReference
    – Shamina
    Commented Nov 24, 2021 at 13:40

2 Answers 2

0

You can try to reload the record after you set the Case Id.

component.set('v.CaseId', 'case-id-here');
component.find('recordLoader').reloadRecord(true);

This will make sure your record is reloaded after Id is updated.

3
  • I am afraid I could do that as I am landing on a record creation page. The other problem I am facing right now is - I have to close the tab that opens up my aura component which then redirects to record creation page. Commented Nov 24, 2021 at 18:41
  • @AustinEvans not sure what you mean. Can you elaborate with an example? When using reloadRecord it is triggering the handleRecordUpdated as you want.
    – tugce
    Commented Nov 25, 2021 at 14:39
  • I would give this approach a try and get back to you after Monday. Thanks. Commented Nov 25, 2021 at 21:07
-2

Make sure that you have a field called Sample__c on the Case object, because the fields mentioned in the fields attribute should be existing/correct standard or custom fields.

For example: try fields="Id,Status" and see if that will work. Thank you.

1
  • The field I specified in my component is valid and it exists on the object definition. So, that's not causing any issue. Any other approach? Commented Nov 22, 2021 at 14:41

You must log in to answer this question.

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