So, in the salesforce UI, users can add buttons and links to objects. But I have an app in a visualforce page that I want users to be able to add the same buttons to.
If this is possible, where do you go to add them, then how do you query them and their executable url so I can create the buttons on my page based on what they added?
Is such a thing possible?
Best Answer
I didn't know if this was possible or not, so I took a look into it.
Starting off, you should take a look at the $Action global variable. It allows you to, in visualforce (most often in conjunction with something like
<apex:outputLink>
or<apex:commandButton>
), reference buttons, links, and actions on a given object.The documentation doesn't do a great job of explaining everything you can do with
$Action
. The typical syntax you'll see isURLFOR($Action.<object name>.<action name>)
likeURLFOR($Action.Opportunity.New)
. You can, however, also use array notation to use string literals to specify the object name and action name. Custom buttons/links/actions can also be referenced with$Action
The next step is to figure out how to get a list of button names. It turns out that you can query the Weblink SObject to do this.
For example, to fetch all of the buttons you have on the
Opportunity
SObject...With the query above, you can present your users with a configuration page where they can select which buttons they want to have included on your App's main visualforce page. You'll need to store user elections somewhere (like a Custom Metadata Type, a Custom Setting, or a full-blown SObject).
At this point, you have all the information you need to display your user-selected buttons in your app's main visualforce page.
The example that I cooked up as a proof of concept doesn't take care of storing/recalling user-selected buttons, but it should serve as a good base for you to work off of.
Controller Extension:
Visualforce page: