0

In a lightning component, I have 2 div, one with a table for example, and in the other I want to display an object record (thanks to its id) and for tthat I have to use the force:navigateToSObject in the javascript controller of the component.

But when I use that, it redirects me to a "new" page (with the record) and I'd like to still see my first div (with the table) is there any way to do that ?

EDIT

I tried to use force:recordView in my component instead of force:navigateToSObject in the controller. But it gives me an error :

Invalid Record Id or Record not accessible.

Here is a part of my component :

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global">
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:handler event="c:NavigateToEvent" action="{!c.NavigateComponent}"/>

<aura:attribute name="id" type="String" access="GLOBAL"/>
<aura:handler name="change" value="{!v.id}" action="{!c.updateRecordView}"/>

{!v.body}
<!--{!v.eventCal}-->
<div id="container">
    <force:recordView recordID="{!v.id}" type="MINI"/>
</div>

and a part of the controller :

updateRecordView: function(component, event, helper) {
    var id = event.getParam("idEvent");
    var container = component.find("container");
    $A.createComponent("force:recordView",
                       {recordId: id,type: "MINI"},
                       function(cmp) {
                           container.set("v.body", [cmp]);
                       });
}

(I used this post to build that part of code)

2
  • 1
    y not use force:recordView tag in the component markup instead of force:navigateToSObject event to display the detail in the div? won't it help in your case?
    – Praveen
    Jun 29, 2016 at 17:08
  • thanks for the idea @Praveen, there is so much functionnalities in lightning that I don't know they exists... ! But I tried what you mentionned and I can't make it works (I updated my post with the code)
    – dou
    Jun 30, 2016 at 8:34

2 Answers 2

2

force:recordView component expected recordId but found recordID in your component markup, that is why you got the below error:

Invalid Record Id or Record not accessible

It is because component attributes, variables you use in controller and helper are all case-sensitive.

With that said, force:recordView automagically refreshes the detail view when the recordId value change, so no need to create the same using $A.createComponent method.

Below is how your component should look.

Component:

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:handler event="c:NavigateToEvent" action="{!c.NavigateComponent}"/>
    <aura:attribute name="id" type="String" access="GLOBAL"/>

    {!v.body}
    <!--{!v.eventCal}-->
    <div id="container">
        <force:recordView recordId="{!v.id}" type="MINI"/>
    </div>
<aura:component
2
  • I change to recordId but I still get the same error. By the way, I tried to create dynamically the force:recordView by only write a createComponent in the controller but it doesn't work too...
    – dou
    Jul 1, 2016 at 7:22
  • @dou can you put an log to check whether {!v.id} contains valid record id or not?
    – Praveen
    Jul 1, 2016 at 8:22
1

This works:

<aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId"> 
    <aura:attribute name="id" type="String"/> 
    <force:recordView recordId="{!v.recordId}"/> 
</aura:component> 

The reason is that v.recordId is already bound for you as documented here:

Configure components for Record Specific Actions

You must log in to answer this question.

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