I want to create a button on the related list which could open up a Screen flow as a modal.
2 Answers
Here's a simple solution without having to create a modal component or code anything.
Requirements:
- Make sure your screen flow has recordId as an input variable to capture the parent record Id.
- Create a new 'action' button on the parent object that contains the related list. Select your screen flow that contains the input variable 'recordId'.
- Place the button on the header of the page and click it. Then make sure to copy the URL (important).
Example URL I copied: /lightning/action/quick/Account.Call_Create_Opportunity_Flow?objectApiName&context=RECORD_DETAIL&recordId=001VC000006TriDYAS&backgroundContext=%2Flightning%2Fr%2FAccount%2F001VC000006TriDYAS%2Fview
In this case, I created the sample action button on the Account by: Object Manager --> Accounts --> new action button 'Call Create Opportunity Flow'.
From the URL you copied earlier, you'll notice a sequence within the parameters after the question mark '?'. If you adjust the values in bold to use the related list object, the model will render like a normal action button all while passing the recordId of the parent.
Replace the items in BOLD with your information:
/lightning/action/quick/ParentObjectAPIName.FlowAPIName?objectApiName&context=RECORD_DETAIL&recordId={!CASESAFEID(ParentObjectAPIName.Id)}&backgroundContext=%2Flightning%2Fr%2F2FParentObjectAPIName%2F{!CASESAFEID(ParentObjectAPIName.Id)}%2Fview
It should look like this:
/lightning/action/quick/Account.Call_Create_Opportunity_Flow?objectApiName&context=RECORD_DETAIL&recordId={!CASESAFEID(Account.Id)}&backgroundContext=%2Flightning%2Fr%2F2FAccount%2F{!CASESAFEID(Account.Id)}%2Fview
What you end up with is the same behavior as a standard action button.
Unfortunately you can't do this directly.
However, you can create a component to house the flow and launch that component in a modal from the list view button. There's an example of this as an answer to this question:
https://developer.salesforce.com/forums/?id=9060G0000005Z2NQAU