How to Pass Parameters to a Lightning Component Quick Action?

Question

I have a Lightning Component that is used as a Lightning Component Quick Action. This component needs to be added to different objects, such as Account and Contact, as a quick action.

The challenge I am facing is determining which object the component was invoked from. While I can retrieve the record Id using:

<aura:attribute name="recordId" type="String" />

This only provides the record’s Id, not the object type. I need a way to pass additional parameters to the Lightning Component Quick Action so that it can determine which object it was launched from. Is there a way to achieve this?

Answer

A straightforward way to determine the object type is by using force:hasRecordId to get the record Id and then making a call to retrieve the object type from it. However, if you want to pass parameters directly to the component without making an additional server call, here are some workarounds:

1. Using the Quick Action API Name to Encode Parameters (Workaround)

Since standard quick actions do not allow passing additional parameters directly, a workaround is to encode a parameter inside the Quick Action’s API name and then extract it inside your component.

For example, when creating the quick action, set its API name in this format:
API Name format:

ParamValue_XXX_QuickActionName

Example: If you create a quick action on the Account object, name it as:

Foo_XXX_Quickie

Inside your LWC component, you can retrieve this API name using CurrentPageReference and parse the parameter value like this:

import { api, wire } from "lwc";
import { CurrentPageReference } from "lightning/navigation";

export default class MyQuickAction extends LightningElement {
    paramValue;

    @wire(CurrentPageReference)
    parseParam(currentPageReference) {
        if (currentPageReference?.type === "standard__quickAction") {
            let quickActionPath = currentPageReference.attributes.apiName; // Example: Account.Foo_XXX_Quickie
            this.paramValue = quickActionPath.split(".")[1].split("_XXX_")[0]; // Extract "Foo"
        }
    }
}

This method allows you to pass one parameter (like an object identifier, mode, or flag) by encoding it in the Quick Action API name. However, it is a workaround and should be used cautiously.

2. Using a Utility Function to Retrieve the Object Type

If you only need the object type and don’t want to use the API name trick, you can use recordId and call a utility function to retrieve the object name dynamically:

public with sharing class RecordUtils {
    @AuraEnabled(cacheable=true)
    public static String getObjectType(Id recordId) {
        return recordId.getSObjectType().getDescribe().getName();
    }
}

Then, call this from your Lightning Component or LWC using Apex imperative call or wire service to fetch the object type.

3. Using Lightning Navigation to Get Additional Context

You can also retrieve navigation context using CurrentPageReference to get details about how the quick action was triggered. This can help in some cases but does not provide object information directly.

import { api, wire } from "lwc";
import { CurrentPageReference } from "lightning/navigation";

export default class MyQuickAction extends LightningElement {
    @wire(CurrentPageReference)
    currentPageReference;

    get objectName() {
        return this.currentPageReference?.attributes?.objectApiName;
    }
}

This works if Salesforce provides the objectApiName in the CurrentPageReference, but it’s not always available in quick actions.
The given JavaScript code is an LWC (Lightning Web Component) designed to be used as a Lightning Component Quick Action in Salesforce. The purpose of this component is to retrieve the object API name (e.g., Account, Contact) of the record on which the quick action was invoked.

api: A decorator that allows a property to be exposed as a public attribute.wire: A decorator used to retrieve data reactively from a wire adapter.CurrentPageReference: A wire adapter from lightning/navigation that provides information about the current page, including the record, object, and navigation context.
export default: This allows the class to be used in other modules.MyQuickAction: The name of the LWC class, which extends LightningElement
The @wire(CurrentPageReference) decorator fetches details about the current page and stores it in the currentPageReference property.The currentPageReference object contains metadata about the current page, such as the type of page (record, app, quick action, etc.), object API name, and navigation attributes.

Since Lightning Component Quick Actions do not have built-in support for passing parameters, the most effective workaround is to encode a parameter inside the Quick Action API name and extract it within the component. If you only need the object type, you can retrieve it using recordId and an Apex method.

Job-Oriented Salesforce Training with 100% Money Back Assurance

Our Salesforce course is carefully structured to give you a strong grasp of the Salesforce platform, equipping you with the essential skills needed to succeed in the CRM industry. Covering key modules like Salesforce Admin, Developer, and AI, the program blends theoretical learning with practical application. Through real-world projects and hands-on exercises, you’ll develop the expertise to tackle complex business challenges using Salesforce solutions. Our skilled instructors ensure you gain both technical proficiency and industry knowledge to excel in the Salesforce ecosystem.

In addition to technical training, our Salesforce training in Mumbai provides personalized mentorship, certification support, and interview preparation to boost your career opportunities. You’ll have access to valuable study materials, practical project experience, and ongoing guidance throughout your learning journey. By the end of the course, you’ll be fully prepared for certification exams and equipped with the real-world problem-solving skills that employers seek. Take the next step in your Salesforce career—join a Free Demo today!

0
Would love your thoughts, please comment.x
()
x