I have 2 quick Action buttons, which call same lightning components.
How should I know on component initialization that which Quick Action triggered lighting component?
Unfortunately that's not possible today. One way I can think of doing this would be having a parent wrapper Lightning component to pass an attribute to the child lightning component to let the child component know about current context. Something like below. This will even work when you have same component in multiple actions on a same page. Only issue is you will end up having that many parent wrapper components means if you use the component at two different places you will end up creating two different parents!
Look at @KeithC answer in How to call a WebService method from a Lightning Component that replaces a Classic JavaScript button?
Pseudo code: In the below example you have 2 different parent components and same child component.
Action1:
<aura:component>
<aura:attribute
<aura:attribute name="context" type="String" default="context1"/>
<!-- Optional coponent attributes here -->
<!-- Optional HTML markup -->
<c:child context={!v.context}/>
</aura:component>
Action2:
<aura:component>
<aura:attribute
<aura:attribute name="context" type="String" default="context2"/>
<!-- Optional coponent attributes here -->
<!-- Optional HTML markup -->
<c:child context={!v.context}/>
</aura:component>
In the meanwhile you could upvote for the idea Ability to pass parameters to lighting component from quick actions in lightning
On a totally different train of thought, if you wanted to navigate to a full-screen Lightning Component you could implement lightning:isUrlAddressable
in your component and have your buttons be link buttons instead. Then each button could pass different parameters to the component.
Be aware that URL addressable components get cached for when you come back to them again. You will want to implement an init method that checks the state parameters, but also an onPageReferenceChanged
method which re-checks the state and re-inits the component to whatever you want it to be when you return to it again.
A hacky workaround to pass one parameter (besides record Id) is to name the quick action API name like so: ParamVal_XXX_QuickActionName
Example: a quick action with API Name Foo_XXX_Quickie created on Account object
Then in your LWC, you can parse the Param Value off the quick action API name like so:
import { api, wire } from "lwc";
import { CurrentPageReference } from "lightning/navigation";
............
@wire(CurrentPageReference)
parseParam(CurrentPageReference){
let quickActionPath = currentPageReference.attributes.apiName; // Account.Foo_XXX_Quickie
let paramValue = quickActionPath.split(".")[1].split("_XXX_")[0]; // Foo
}