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 ?