0

I'm trying to create a link to redirect to Contact. Component

    <aura:attribute name="Contacts" type="Contact[]"/>
    <aura:iteration items="{!v.Contacts}" var="con">
<tr>
<td><a onclick="{!c.navigateToRecord}" style="width:100%;">{!con.Name}</a></td>
<td> {!con.Email} </td>
<td> {!con.Contact_level__c} </td>
<td> {!con.Account.Name} </td>
<td> {!con.Owner.Name} </td>
<td> {!con.CreatedBy.Name} </td>
<td> {!con.CreatedDate} </td>

Controller

navigateToRecord : function(component, event, helper) {
     var navEvent = $A.get("e.force:navigateToSObject");
     navEvent.setParams({
          recordId: component.get("v.contact").Id,
          slideDevName: "detail"
     });
     Console.log("hey");
     navEvent.fire();

I get this Message

Cannot read property 'setParams' of undefined

Help me PLS, WHY?

1

This means that force:navigateToSObject is not supported in your current code. The documentation states:

This event is handled by the one.app container. It’s supported in Lightning Experience, the Salesforce app, and Lightning communities.

If you're using something else, like Lightning Out, you need to use a different syntax, such as window.location.

| improve this answer | |
  • What am I suppose to do to deal with it? – Andrey Beloborodov Aug 27 at 20:51
  • @AndreyBeloborodov It depends on the context. If the event is null, that means that you need to sforce.one (if available) or window.location. – sfdcfox Aug 27 at 20:54
  • I'm in lightning, I don't understand what does it mean =( – Andrey Beloborodov Aug 27 at 21:18
  • @AndreyBeloborodov There's things like Lightning Out, etc. Without knowing more about the code is running, I don't have a specific answer. The point is, you only get this event if you're actually in Lightning. – sfdcfox Aug 28 at 1:24

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.