I am invoking AuraComponent from vf page and displaying selected contacts.Now on click of cancel button in component I tried to use Navigation mix and force:navigatetoSobject to navigate to listview/recordpage,both are not working.Is there any way for navigation when component invoked from vf page?
[SalesForce] How to navigate(to list view/recordpage) when Component(Aura/LWC) is invoked from vf page
Related Solutions
You could try firing force:refreshView
during an aura:locationChange
event. Add the locationChange
handler to your component.
<aura:handler event="aura:locationChange" action="{!c.update}"/>
And handle the event in your JS code.
update : function (component, event, helper) {
// Get the new location token from the event if needed
var loc = event.getParam("token");
$A.get('e.force:refreshView').fire();
}
NavigationMixin controls navigation to Salesforce pages or the creation of URLs to those pages. You can go to edit, view, etc. Here is the documentation: https://developer.salesforce.com/docs/component-library/bundle/lightning-navigation/documentation.
Here is the js class, notice the info in "header", it is really important:
import { NavigationMixin } from "lightning/navigation";
import { CloseActionScreenEvent } from "lightning/actions"; //if you want to close a page, but you don't need to if you navigate
export default class btnCreateShipment extends NavigationMixin(
LightningElement
) {
navigateToListView() {
// Navigate to the Contact object's Recent list view.
this[NavigationMixin.Navigate]({
type: 'standard__objectPage',
attributes: {
objectApiName: 'Contact',
actionName: 'list'
},
state: {
// 'filterName' is a property on the page 'state'
// and identifies the target list view.
// It may also be an 18 character list view id.
filterName: 'Recent' // or by 18 char '00BT0000002TONQMA4'
}
});
}
navigateToRecordEditPage(recordId) {
// Opens the record modal
// to view a particular record.
this[NavigationMixin.Navigate]({
type: 'standard__recordPage',
attributes: {
recordId: recordId,
actionName: 'edit'
}
});
}
}
Finally, I would suggest you set up LWC Recipes, if you haven't already... many of the basic things you will want to do are built out. This will save you hours and hours of time: https://github.com/trailheadapps/lwc-recipes
Good luck!
Best Answer
You can try this
sampleCmp.cmp
sampleCmp.js
Aura Application
VF page