Hi, does anyone know how to stay on opportunity screen when adding new record to related list via custom button?
I have added custom button "New Air Lane" to show pop-up to create new record to the related list "Opportunity Lane".
The custom button is the list button with URL in order to set initial value.
The issue is that once new record is created, Salesforce bring the screen to "Opportunity Lane" tab.
However, I would like Salesforce to just close the pop-up and allow me to continue adding more records.
Is there any way to modify custom button behavior in the setting?
@Yoshitaka Ono Here's a simple solution using a Screen Flow! I believe you will find this very useful in certain scenarios where dynamic logic is needed.
Create a Screen Flow
- Add a Get Records element to the start of the flow.
- Set the condition requirements as follows: Id Equals recordId. Where recordId is a new text variable with available for input checked.
- Add a Screen element to the flow after the Get Records.
- Example: I added a Get Records for the Account. Then for the Screen added a display text element to validate the output: Id (Account Id) and Name (Account Name).
Create a New Action button on the parent object that contains the related list.
- Action Type = Flow
- Flow = Create Opportunity & Quote
- Label = 'Create Opportunity' (this will be the name of the button that displays along with the header text in your modal)
- Name = Create_Opportunity (API name used in the link)
- Example: Object Manager --> Account --> Buttons, Links, and Actions --> New Action
Place the button on the header of the page and click it.
- In this case, I added it to the top of the Account page.
- Then copy the URL *Important*
/lightning/action/quick/Account.Create_Opportunity?objectApiName&context=RECORD_DETAIL&recordId=001VC000006TriDYAS&backgroundContext=%2Flightning%2Fr%2FAccount%2F001VC000006TriDYAS%2Fview
Create a new custom button on the child object.
- Label = 'New'
- Name = New_Opportunity
- Select List Button
- Content Source = URL
- Paste the URL you copied from the action button created in the first step above. Note: You'll notice a sequence within the action parameters after the question mark '?'. If you adjust the values in bold, the model will render like a normal action button all while passing the recordId of the parent.
- Example: Object Manager --> Opportunity --> Buttons, Links, and Actions --> New Button or Link.
Replace the items in BOLD and BLUE Hyperlinked in this case with your information:
- DomainNameHere/lightning/action/quick/ParentObjectAPIName.ActionButtonAPIName?objectApiName&context=RECORD_DETAIL&recordId={!CASESAFEID(ParentObjectAPIName.Id)}&backgroundContext=%2Flightning%2Fr%2F2FParentObjectAPIName%2F{!CASESAFEID(ParentObjectAPIName.Id)}%2Fview
For example, your new URL will look like this:
- https://salesforce.lightning.force.com/lightning/action/quick/Account.Create_Opportunity?objectApiName&context=RECORD_DETAIL&recordId={!CASESAFEID(Account.Id)}&backgroundContext=%2Flightning%2Fr%2F2FAccount%2F{!CASESAFEID(Account.Id)}%2Fview
Add the Custom Button to your Related List
- Go back to the page layout for the parent object and select the wrench to edit the related list.
- Under Custom Buttons, select the "New" URL button you just created to make it available.
SURPRISE! What you end up with is a custom screen flow in a modal window that mimics the same behavior as the standard New button on a related list.
If you need to perform the same natural modal behavior from a list view, refer to this article: https://www.reddit.com/r/salesforce/comments/uli6d3/calling_a_flow_or_lightning_web_component_from/