I am creating an LWC, which is supposed to call a global action (a create case record) on click of a button. The reason for having this is there are some pre-processing and pre-population of values that I want to do in LWC and then call the global action (which will have minimal onscreen fields for the users). But the quick action is not loading rather giving error - "Page doesn't exist
Enter a valid URL and try again"
As of now it is placed in the Contact record page. The preprocessing through wired method is working properly. In future this LWC will be enhanced for different situation and different record pages etc. But not sure why the global action is not loading when button is clicked. In the JS you will see I have commented out for now the pre-population (State attribute) to just to see the global action pop up appear. But nothing is working. Can anyone help me where am I going wrong?
The full code is like this -
createCaseUsingGlobalAction.js
import { api, LightningElement, track , wire} from 'lwc';import { NavigationMixin } from 'lightning/navigation';import { getRecord, getFieldValue } from 'lightning/uiRecordApi';import AccountId_FIELD from '@salesforce/schema/Contact.AccountId';export default class createCaseUsingGlobalAction extends NavigationMixin(LightningElement) { @api recordId; // If your LWC is on a record page, this will hold the record ID @api accountId; @track isLoading = false; @track error; @wire(getRecord, { recordId: '$recordId', fields: [AccountId_FIELD] }) wiredRecord({ error, data }) { console.log('#4 record Id: ', this.recordId); console.log('AccountId_FIELD: ', AccountId_FIELD); console.log('data: ', data); if (data) { this.accountId = getFieldValue(data, AccountId_FIELD); console.log('found Account Id: ', this.accountId); } else if (error) { console.error('Error retrieving record:', error); } } handleCreateCase() { this.isLoading = true; // Show a loading indicator this.error = null; this[NavigationMixin.Navigate]({ type: 'standard__globalAction', attributes: { globalActionName: 'Create_Case_POC2' // Replace with your global action's API name } // , // state: { // // Optional: Pass default field values or context to the global action // // For example, if your LWC is on an Account record page: // // defaultFieldValues: { // // AccountId: this.recordId, // // Status: 'New' // Example default value // // } // // defaultFieldValues: { // // ContactId: this.recordId, // // AccountId: this.accountId, // // Origin: 'Web', // // Subject: 'Case created from LWC', // // Priority: 'Normal', // // Status: 'New' // // } // } }) .then(() => { this.isLoading = false; // Hide loading indicator // Handle successful navigation (e.g., show a toast message) console.log('Global action opened successfully'); }) .catch(error => { this.isLoading = false; // Hide loading indicator this.error = error; // Handle navigation error (e.g., show an error toast message) console.error('Error opening global action:', error); this.showToast('Error', error.message, 'error'); }); } showToast(title, message, variant) { const event = new ShowToastEvent({ title: title, message: message, variant: variant, }); this.dispatchEvent(event); }}
createCaseUsingGlobalAction.html
<template> <lightning-button label="Create Case" onclick={handleCreateCase} variant="brand" disabled={isLoading}></lightning-button> <template if:true={isLoading}> <lightning-spinner alternative-text="Loading..." variant="brand"></lightning-spinner> </template> <template if:true={error}> <div class="slds-text-color-error">{error.message}</div> </template></template>
createCaseUsingGlobalAction.js-meta.xml
<?xml version="1.0" encoding="UTF-8"?><LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata"> <apiVersion>63.0</apiVersion> <isExposed>true</isExposed> <targets> <target>lightning__RecordPage</target> </targets> <targetConfigs> <targetConfig targets="lightning__RecordPage"> <objects> <object>Contact</object> </objects> </targetConfig> </targetConfigs></LightningComponentBundle>