0

I am working on a lightning component where on click contact link I have to open that contact in edit mode. But throwing this error: enter image description here

Please find my code below: I am using it in :

<aura:component > 
    <aura:attribute name="showcontact" type="Contact[]"/>

    <table class="slds-table slds-table--bordered slds-table--cell-buffer" style="margin-top:50px;"> 
        <thead> 

        <div style="text-align:center;font-size:25px">
            Selected Contacts
        </div>

        <tr class="slds-text-heading--label">
            <th scope="col">
                <div class="slds-truncate" title="Contact Name"><b>Contact Name</b></div>
            </th>
            <th scope="col">
                <div class="slds-truncate" title="Phone"><b>Phone</b></div>
            </th>
            <th scope="col">
                <div class="slds-truncate" title="Email"><b>Email</b></div>
            </th> 
        </tr>
        </thead>
        <tbody>
        <aura:iteration items="{!v.showcontact}" var="con">
            <tr>
                <th> 
                    <a href="javascript:void(0);" onclick="{!c.editContact}" data-value="{!con.Id}">
                        {!con.Name}
                    </a>
                </th>
                <th> 
                    <div class="slds-truncate" >
                            {!con.Phone}
                    </div> 
                </th>
                <th>        
                    <div class="slds-truncate">
                        {!con.Email}
                    </div> 
                </th>
            </tr> 
        </aura:iteration>
    </tbody>
    </table>
</aura:component>

Controller:

({
    editContact: function (component, event, helper) {
        var rectarget = event.currentTarget;
        var idstr = rectarget.getAttribute("data-value"); 
        console.log('****'+idstr)
        var editRecordEvent = $A.get("e.force:editRecord");
        editRecordEvent.setParams({
            "recordId": idstr
        });
        editRecordEvent.fire();        
    }
})
  • whats the value you are getting in idstr...please use console.log('****',idstr).??? and alsp try o use like this var rectarget = event. event.target.Id; – Annappa PH May 12 '18 at 5:39
  • I am getting contact id here. – SFDC 44 May 12 '18 at 5:42
  • make on Id hard code and check that. I think that you maynot get that error (for testing purpose )something like this:<a onclick="{!c.editContact}" data-conId="0037F00000O7Dj7QAF">0037F00000O7Dj7QAF</a> – Annappa PH May 12 '18 at 5:50
  • 2
    Please note: This event is handled by the one.app container. It’s supported in Lightning Experience, the Salesforce app, and Lightning communities. If you are not in this context, this event won't be available – Caspar Harmer May 12 '18 at 7:15
  • I am using it in : <aura:application extends="force:slds"> <c:ShowContactsOnClickAccount/> </aura:application> How can I show it here ? – SFDC 44 May 12 '18 at 7:18
1

If you are adding lightning component to a Lightning app and viewing lightning app from developer console then e.force:editRecord do not work because force events are handled only in one/one.app. so please try to add a lightning component to the page using app builder.

| improve this answer | |

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