0

I am new to Lightning component I have created a simple app for my sand box. i which i am trying to access my record home page in the first step I have created simple list of task in which I have got all the record from the Apex controller. Aura lighting component.

<aura:componentimplements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction,force:hasRecordId " access="global" controller="TaskController">
  <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <aura:attribute name="lstTask" type="Task[]" />  
    <aura:attribute name="recotdId" type="Id"/>
  <article class="slds-card"  >
  <div class="slds-card__header slds-grid" Style=" height: 5rem; background-color:#dddbda;">
    <header class="slds-media slds-media_center slds-has-flexi-truncate" >
      <div class="slds-media__figure">
        <span class="slds-icon_container slds-icon-standard-contact" title="Task">
          <span class="slds-assistive-text">Task</span>
        </span>
      </div>
      <div class="slds-media__body">
        <h2 class="slds-card__header-title">
          <a href="javascript:void(0);" class="slds-card__header-link slds-truncate" title="Opened Tasks (3)">
            <span>Opened Tasks </span>
          </a>
        </h2>
      </div>
    </header>
  </div>
  <div class="slds-card__body slds-card__body_inner">
    <ul class="slds-grid slds-wrap slds-grid_pull-padded">
      <aura:iteration items="{!v.lstTask}" var="task">  
      <li class="slds-p-horizontal_small slds-size_1-of-1 slds-medium-size_1-of-1"  onselect="{!c.recordDetail}"  Style="border-bottom: #DCDCDC solid 0.07rem; Padding-bottom:1rem;">
        <article class="slds-tile slds-media slds-card__tile slds-hint-parent">
          <div class="slds-media__figure">
            <span class="slds-icon_container slds-icon-standard-contact" title="Description of icon when needed">
              <span class="slds-assistive-text">Contact</span>
            </span>
          </div>
          <div class="slds-media__body">
            <div class="slds-grid slds-grid_align-spread slds-has-flexi-truncate">
            </div>
            <div class="slds-tile__detail"   >
              <dl class="slds-list_horizontal slds-wrap">
                <dt class="slds-item_label slds-text-color_weak" title="First Label">Stage:</dt>
                <dd class="slds-item_detail slds-truncate" title="Description for first label">{!task.Stage}</dd>
                <dt class="slds-item_label slds-text-color_weak" title="Second Label">Name:</dt>
                <dd class="slds-item_detail slds-truncate" title="Description for second label">{!task.Who.Name}</dd>
                <dt class="slds-item_label slds-text-color_weak" title="Second Label">Stage:</dt>
                <dd class="slds-item_detail slds-truncate" title="Description for second label">{!task.Status}</dd>
                <dt class="slds-item_label slds-text-color_weak" title="Second Label">Due Date:</dt>
                <dd class="slds-item_detail slds-truncate" title="Description for second label">{!task.ActivityDate}</dd>
                <dd class="slds-item_detail slds-truncate"  aura:id="taskId"  > {!task.Id}  </dd> 
                  <aura:set attribute="recotdId" value="{!task.Id}"></aura:set> 
                  <span class="slds-float--left" >
                     <lightning:button  aura:id="botton1" label="{!task.Id}"  />
                 </span>
                  <span class="slds-float--left" >
                     <lightning:button label="View"  onclick="{!c.recordDetail}" />
                 </span>

              </dl>
            </div>
          </div>
        </article>
      </li>
      </aura:iteration>
    </ul>
  </div>
  <footer class="slds-card__footer">
  </footer>
</article>
</aura:component>

this code is working fine with for listing the Tasks records. with the following component

doInit: function(component, event, helper) {
    var action = component.get("c.openTask");
    action.setCallback(this, function(e) {
        if(e.getState()=='SUCCESS'){
            var result=e.getReturnValue(); 
            component.set("v.lstTask",result);
        }
    });
    $A.enqueueAction(action);
}

and the Apex controller.

 @AuraEnabled
public Static List<Task> openTask(){
   List<Task> tasks = new List<Task>();
   tasks = [SELECT Id, Subject,Status,ActivityDate, Who.Name,What.Type FROM Task where  Status='Open'];
   System.debug('Task :::::::'+tasks);
   return  tasks;
}

this code is working fine.

In the second step I am trying to access the record home page for this I have created a button and place the onClick event on it. ie

 <span class="slds-float--left" >
                 <lightning:button label="View"  onclick="{!c.recordDetail}" />
             </span>

and here is the component I am calling on click event.

  recordDetail : function (component, event, helper) {
var recordId= component.get("v.lstTask.Id")
//      "recordId": "00T1g000005U3irEAC",    

var recordId= component.get("v.lstTask.Id");
var navEvt = $A.get("e.force:navigateToSObject");


    navEvt.setParams({
   "recordId": recordId,
  "slideDevName": "related"
});
navEvt.fire();

}

when ever I click on the button it give the following error. enter image description here

please help me through this.

also keep it mind this code only work on salesforce1 so I am using salseforce1 chrome simulator app for this and it doesn't have any debugger.

Thanks Advance, Shafee

1 Answer 1

0

Place the record ID on the nearby span element, then refer to that:

<span class="slds-float_left" data-record-id="{!task.Id}">

...

recordDetail: function (component, event, helper) {
  var recordId = event.target.closest("[data-record-id]").dataset.recordId;
  // ... rest of logic ...
2
  • Now I am getting this error Uncaught Action failed: c:OpenedTaskComponent$controller$recordDetail [Cannot read property 'dataset' of null]
    – shafi jan
    Aug 7, 2019 at 0:33
  • Thanks It works.
    – shafi jan
    Aug 7, 2019 at 10:12

You must log in to answer this question.

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