I built a Lighting Web component that opens the standard Opportunity creation Page after a Lighting button is clicked.
<template>
<lightning-card
title="NavToNewRecordWithDefaults"
icon-name="custom:custom96"
>
<lightning-button
name="new-with-defaults"
label="Go to New Sales Case with Defaults"
class="slds-var-m-around_medium"
onclick={navigateToNewContactWithDefaults}
></lightning-button>
</lightning-card>
import { LightningElement } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
export default class NavToNewRecord extends NavigationMixin(LightningElement) {
navigateToNewContactWithDefaults() {
// default fields to be added
const defaultValues = encodeDefaultFieldValues({
});
// eslint-disable-next-line no-console
console.log(defaultValues);
this[NavigationMixin.Navigate]({
type: 'standard__objectPage',
attributes: {
objectApiName: 'Opportunity',
actionName: 'new'
},
state: {
defaultFieldValues: defaultValues
}
});
}
}
Salesforce reference arcticle https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.use_navigate_default
The question:
How to override the "save" button of the opportunity page such that i can call another method instead of having the redirect to the new opportunity record?
Basically i want to achieve what is described in this idea but with Lighting web components:"Callback method for force:createRecord event to redirect or refresh after save" https://trailblazer.salesforce.com/ideaView?id=0873A0000003V4hQAE