8

I'm trying to access current record id in a Lightning Component when put into Utility Bar. But it comes out to be empty all the time. I've implemented force:hasRecordId interface in my component but recordId attribute remain empty when I launch the component in Utility Bar.

Is there a way we can achieve this function of reading current record id in utility bar?

  • Did you make any progress with this? I'd love to be able to get some context in my component! – Matt Lacey Mar 7 '17 at 12:21
  • Nopes, nothing yet. – VarunC Mar 7 '17 at 13:42
2

I believe this may have been resolved in the Winter '18 release. I just added a component to the utility bar that implements force:hasRecordId and it does pull it in.

For reference, here is the relevant component attributes:

<aura:component implements="force:hasRecordId,force:lightningQuickAction,flexipage:availableForAllPageTypes">

And here is the JS controller that fires on init:

handleRecordChange: function(cmp, evt, hlp) {
    // only call server if user is on step 1
    var step = cmp.get("v.step");
    if (step == 1) {
        var recId = cmp.get("v.recordId"); 
        if (recId != null) {
            // delegate to helper
            hlp.getRecordInfo(cmp, cmp.get("v.recordId")); 
        } else {
            cmp.set("v.recordContext", false); 
            cmp.set("v.step",0); 
        }
    }
}

I think for this to work your Lightning Component needs to be on API version 41.0. You can adjust this by clicking the "Bundle Version Settings" button in the cloud dev console.

Hope this helps!

  • Hey @kev4ev, do you have an example you can share? Just tried in a Winter '18 org and it appears it's still not working. – Gus Melendez Oct 20 '17 at 20:57
  • @GusMelendez Just updated my answer with some sample code. Note the last part regarding setting your component API version to 41.0 – alphaBytes Oct 23 '17 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.