I'm trying to do something, but I am stuck on this scenario. So, I have a lwc that can be placed on multiple pages (Record Pages, Home Pages etc). The users will define the component destination, in a custom metadata record, that is passed to the component like this:

<property name="customSettings" label="Custom Settings" type="String" datasource="apex://MyCustomSettings" required="true" />

That class will query a Custom Metadata Type, for specific records, that also include the user prefered page destination (eg. Home Page).

What I am trying to do, is a way to block the user, to place the component in another type of page, other than the one he defined in the CMT.

So far, the only way I found was this: on the lwc to have template that gets displayed instead of the component

<template lwc:if={error}><p class="text">Check the error on the component</p></template>

On the Javascript side, I have this method:

pageReferenceValidation(currentPageReference, userChoice) {
       if (currentPageReference !== userChoice) {
           const evt = new ShowToastEvent({
               title: 'Toast Error',
               message: 'Page reference error',
               variant: 'error',
               mode: 'sticky'
           throw new Error('Page reference error');
   } catch(err){
       this.error = err;

The problem is that I can't block the user, when he edits the flexipage, to proceed with the wrong setup. He will see something like this: enter image description here but he will still be able to save the page.

Do you guys have any suggestions on how can I reach the described behaviour?

Thanks in advance for any advice!

1 Answer 1


I would turn this around and make sure you have a mandatory property on your LWC which is the selection of a relevant Custom Metadata Type record. You can ensure that this property can only be set to a Custom Metadata Type record identity where that Custom Metadata Type record relates to the type of page into which the component is being added. If there are no CMT records for the type of page, then the user won't be able to select a value for this mandatory property and therefore will not be able to save and publish the page.

You address this by implementing a VisualEditor.DynamicPickList that looks at the given VisualEditor.DesignTimePageContext and searches for Custom Metadata Type records that match the context, making just the matches available for selection.

NB: If there are no selections, ensure the default value is returned as null.

  • 1
    Thanks a lot, Phil W for opening my eyes. Already had the property, I just changed the logic to filter the CMT records.
    – blanco17
    Aug 31, 2023 at 10:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .