I need to create a LWC that will redirect the user to a different URL

The URL should be built with URL params taken from different fields

For this task, it seems like Quick Actions for LWC should be the right approach:


With this technology, you need to implement lightning__RecordAction in your meta file and then you can add this component as and action to the object

Now, I want to create this component as a generic one - so it could be added in all object record page and I want to be able to configure it so it can use different URLs, different fields etc.

The problem is - if I add lightning__RecordAction implementation in the meta file, I cannot add to it properties:

enter image description here

Also, if I could add the properties to it, when I add the LWC as an action - I cannot configure anything there, also in the record page editor where I add the dynamic action, there are no places to set these properties

Can this be done?

Or maybe any other way this could be implemented?

1 Answer 1


fields and URL could be the fields of a Custom Metadata whose label is the Object's API name.
Then you'll need an apex method annotated with @AuraEnabled(cacheable=true) that takes a String (objectApiName) as input and return the instance of your CMT.

public static YourCustomMetadataType__mdt getParameters(String objectApiName) {
    return YourCustomMetadataType__mdt.getInstance(objectApiName);

In the JS you'll need to import that method and an @api objectApiName property, so the record page will set it to the API name of the current object. Finally you should wire the apex method


@wire(getParameters, { objectApiName: '$objectApiName' })
fetchParameters({ data, error }) {
    if (data) {
        this.fields = data.fields__c;
        this.targetURL = data.URL__c;
        // handle fields
    } else if (error) {
        // do something

By the way, if you just need to open a new url, you don't need a screen action, but a headless one, so in the xml the actionType value should be changed to Action

  • Thank you @RubenDG This is a nice solution But it would allow me to add one button like this per object, so if I would like to open multiple links on the same page, this would not help Nov 28, 2022 at 13:27

You must log in to answer this question.

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