1

I have a lightning component hosted in Visualforce page. Lightning Experience is not enabled and it is still Salesforce Classic. I have records displayed in data table. When record name is clicked I want to navigate to record detail page.

Below is my code

COMPONENT

<aura:component >
    <aura:attribute name="CurrentItem" type="Company__c" /> 

    <tr>                  

       <td data-label="Name">
           <div class="slds-truncate" title="{!v.CurrentItem.Name}"><a href="" onclick = "{!c.navigateToRecordPage}">{!v.CurrentItem.Name}</a></div>
       </td>



       <td data-label="City">
           <div class="slds-truncate" title="{!v.CurrentItem.City__c}">{!v.CurrentItem.City__c}</div>
       </td>                      
       <td data-label="State">
           <div class="slds-truncate" title="{!v.CurrentItem.State__c}">{!v.CurrentItem.State__c}</div>
       </td>                        
    </tr>

</aura:component>

CLIENT JS CONTROLLER

({
    navigateToRecordPage: function(component, event, helper) {

        //var parentrec = component.get("v.CurrentItem");
        //sforce.one.navigateToSObject(parentrec.Id);


        //but it throws error when component is in VF page and lightning experience // is not enabled, it is still salesforce classic                

        var navEvt = $A.get("e.force:navigateToSObject");
        var parentrec = component.get("v.CurrentItem");
        console.log(parentrec.Id);        
        navEvt.setParams({
        "recordId": parentrec.Id        
        });
        navEvt.fire();

    }

})

Below are various options I used to do navigation to record detail page but I am receiving error for all of them.

OPTION 1

Using force:navigateToSObject - ERROR - Action Failed [Cannot read property 'setParams' of undefined] Failing descriptor:

OPTION 2

Using sforce.one.navigateToSObject - ERROR Action Failed [sforce is not defined] Failing descriptor

OPTION 3

hardcoding link in href attribute like "/objectid" EXCEPTION - receiving SAME ORIGIN EXception

I have similar code using force:navigateToSObject working correctly in another org which has Lightning Experience enabled. I assume these issues could be related to Salesforce Classic and related to the containers.

Any idea how I can get around this without switching on Lightning Experience ?

2 Answers 2

0

You can try using plain old JavaScript for classic like

window.location.assign=url here

may want to detect whether you are inside Lightning container or classic and based on that for classic use simple window navigation

15
  • Mohith, Could you please clarify ? Is this not going to be SAME ORIGIN issue ?
    – apn
    Dec 24, 2016 at 2:46
  • It's not going to give you same origin as you are redirecting browser window to new url .Have you tried it ? Dec 24, 2016 at 2:48
  • I changed the code as below but still seeing the same origin error ({ navigateToRecordPage : function(component, event, helper) { var parentrec = component.get("v.CurrentItem"); window.location.href= "/" + parentrec.Id; } })
    – apn
    Dec 24, 2016 at 2:52
  • Are you using Lightning out on vf? Dec 24, 2016 at 2:57
  • Yes, I have Outer component in VF page. Outer component uses another inner component. Code snippet given in the question is inner component's code. Click event is for inner component
    – apn
    Dec 24, 2016 at 3:00
0

So below is the resolution to this issue, I was receiving below error, Refused to display 'https://xxxx.my.salesforce.com/xxxxxx' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN' I had "Development Mode" switched on. After switching it off, I was able to navigate without any errors.

Hope this helps.

You must log in to answer this question.

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