[SalesForce] Show a button that shows on related list
I wonder if we could create a button or list that can be displayed on the related section.
Now, If a user clicks on that button then a component should be called or certain record of that object needs to changed.
Can we do this in Lightning?
Best Answer
Yes, you can create a List Button on the object, then add it to the related list for the object where the related list appears. Note that this process will add the button in both LEX and Classic, so you will not need to write two separate versions.
Create a Visualforce Page
Create a Visualforce page that has the recordSetVar and standardController attributes defined. This allows the Visualforce page to be referenced by a list button. This page should use the StandardSetController's getSelected method to retrieve the records that were selected (if necessary).
Create a Custom Button
Create a custom button on the object that you want the button to appear for. In your case, it is the Access Request object. If you want users to be able to select which records to revoke, check the "Show checkboxes" option on the button, which allows users to select up to 200 records and then click the button to hand those ID values to the Visualforce page defined above.
Add to Related List
Finally, go to the parent object, edit its page layout, and add the custom button to the related list by editing it, choosing the Buttons category, and adding your custom button to the list of selected buttons.
A typical pattern to implement an requirement like that is to create a Visualforce Page along with an APEX controller. Just navigating to the related object will not work.
You also can't use Views, because unlike Reports you can't bypass url-parameters as filter criteria:
Closest thing you can get without App and without writing code seem to be the workaround mentioned by @KeithC. The URL pattern looks like
/a04?rlid=00Nb0000002Aq4E&id=a0Xb00000000CrD
It consists of the following components:
a04 is the keyprefix of the child entity
rlid is the Related List Id which Salesforce provides automatically. This will vary an may be only obtainable using the "Go to list" link. The link is only visible, if you have more related items than the current threshold (controlled by e.g. &rowsperlist=10 on the Object View of the master item or by the Always show me viewer / more records per related list).
id is the record id of the master object
Keep in mind that you may end up in hardcoding some Ids in the link. That may break you button when deploying it to different Orgs.
So as a conclusion, I would strongly advocate using either an App or a Visualforce Page for Bulk editing.
Which goes into detail on how to avoid using JavaScript buttons - which ironically includes custom related list buttons - but it doesn't seem to cover your specific use case. It actually advises not using javascript buttons and using lightning component quick actions instead which you have said you tried and that it works but it doesn't provide the exact experience you're looking for.
The last thing I can think of is that you can hide the related list from your page and build a lightning component that looks and acts like the same related list. This will allow you to add a button that could then pull in your other component.
Best Answer
Yes, you can create a List Button on the object, then add it to the related list for the object where the related list appears. Note that this process will add the button in both LEX and Classic, so you will not need to write two separate versions.
Create a Visualforce Page
Create a Visualforce page that has the recordSetVar and standardController attributes defined. This allows the Visualforce page to be referenced by a list button. This page should use the StandardSetController's getSelected method to retrieve the records that were selected (if necessary).
Create a Custom Button
Create a custom button on the object that you want the button to appear for. In your case, it is the Access Request object. If you want users to be able to select which records to revoke, check the "Show checkboxes" option on the button, which allows users to select up to 200 records and then click the button to hand those ID values to the Visualforce page defined above.
Add to Related List
Finally, go to the parent object, edit its page layout, and add the custom button to the related list by editing it, choosing the Buttons category, and adding your custom button to the list of selected buttons.
You can read more about it in Adding Custom List Buttons using Standard List Controllers.