In a Lighting Web Component, you can import the lightning-navigation service function to redirect a User to another page in Salesforce. See more on where you can use the lightning-navigation service here. This can be used to redirect a user to the QLE.
To use the lightning-navigation service in your LWC, you must import the NavigationMixin
function from the lightning-navigation
service. You must extend the components base class with NavigationMixin
to gain access to its APIs.
In the following example, a User clicks a button that calls the saveMethod()
. This method calls an Apex Controller that has also been imported called createdNewQuote
. This Apex Method takes the Opportunity record Id as a parameter, which is found using the $recordId
syntax and the fact that this LWC is on an Opportunity detail page. The Apex Controller returns a newly created Quote object and it's Id
. In the callback method, a url is created using the returned Quote objects record Id
.
This url is then used in the NavigationMixin.Navigate
method. To redirect a User to the QLE, the type
must be set to standard__webPage
which is used to redirect users an external URL, but works to redirect a User to a VisualForce page as well.
import { LightningElement, track, api, wire } from 'lwc';
import createNewQuote from '@salesforce/apex/apexController.createNewQuote';
import { NavigationMixin} from 'lightning/navigation';
export default class lwc_class extends NavigationMixin(LightningElement) {
@api recordId;
saveMethod(){
createNewQuote({recordId: '$recordId'})
.then( result => {
let link = '/apex/sbqq__sb?scontrolCaching=1&id=' + result.Id
+ '#quote/le?qId=' + result.Id;
this[NavigationMixin.Navigate]({
type: 'standard__webPage',
attributes: {
url: link
},
true // Replaces the current page in your browser history with the URL
});
})
.catch((error) => {
console.log('Error: ', error);
});
}
}
}