1

The Problem

I need to embed a button to trigger a screen flow on a Visualforce page. This is because I'm adding a tab for action buttons to a modal window from a managed package (TaskRay), and for custom modal tabs TaskRay only accepts Visualforce pages or Screen Flows, and Screen Flows do not have a button component. I added a custom button to the TaskRay Task custom object to trigger this flow, and it works fine as a quick action on the record page, but I need it on this modal as well. I have a lot of programming experience and quite a bit of Salesforce experience, but no experience at all with Apex code or Visualforce, and little web programming experience in general, so I'm open to suggestions if there is a better way to accomplish my goal or if my priors are wrong.

An additional complication is that the screen flow uses the implicit recordId variable to look up the record that it was triggered from. I will need to be able to get pass the record ID through the Visualforce page into the flow in some manner for it to work correctly (I'm open to creating a new flow if needed to capture the record ID differently).

My Solution So Far

Currently, from the research I've done, it seems to me there is no way to add a custom button/action from a custom object to a Visualforce page directly. My current line of thinking is that using the <apex:commandButton/> element is the best bet, however, it seems the action attribute doesn't have a way to reference a custom action directly. The documentation describes the $Action shorthand as being for standard Salesforce actions only, and my tests seem to confirm this. It looks like the solution, then, is to create a custom Apex Controller with an Action Method that invokes the custom action, which I can then reference from the <apex:commandButton/> tag. What's not clear is whether this is a good solution and how to invoke the custom action within the Apex code. Once that part is established, I should be able to use code like this (from the previous link):

account = [select id, name, site from Account 
                       where id = :ApexPages.currentPage().getParameters().get('id')];

but with the TaskRay Task object to get the record ID, and then use a URL parameter in the code that invokes the custom action to pass it through to the flow.

In Summary

I apologize if this is confusing or a lot to digest. All this jargon is giving me a headache too. Basically, I want to use <apex:commandButton\> on a Visualforce page to trigger a custom screen flow action on a custom object, and I think the solution is to use a custom Apex Controller to do so. If anyone can point me in the right direction with resources to educate myself on how to accomplish that, that would be great. And if everything I'm saying is wrong and there's a better way, I'm open to that, too. It does seem like there should be a much simpler way to do something as basic as adding a custom action button to a Visualforce page, but unfortunately it isn't a very searchable problem and I wasn't able to turn up a cleaner solution (most results deal with triggering Visualforce pages from actions/buttons, rather than the opposite). I greatly appreciate everyone's time who is reading this.

4
  • Hi, and welcome to SFSE! This is excellent for a first question, with quite a lot of detail. However, I'm pretty sure that your approach won't work. What does this action do? Perhaps there's another simple way to get around it? Have you looked into creating a custom flow component to handle this? If you'd take a moment to edit your question to provide some background information, I think that'd help us better help you.
    – sfdcfox
    Commented Dec 8, 2023 at 22:39
  • You're overthinking this, one VF page has a button that redirects to a second VF page (or renders a section on the page that exposes the flow:interview component) that embeds the Flow Interview as documented here and this example shows how to pass recordId to flow
    – cropredy
    Commented Dec 9, 2023 at 0:11
  • @cropredy that is working great, thank you! I knew I was probably overengineering this somehow. Using another Visualforce page as the action for <apex:commandButton> works great, and I just have to get the recordId flowing through. Incidentally, do you know if it's possible to have the button open a modal? Currently it's just opening in place of the source Visualforce page, which is fine, but it would be nice if it could open a modal the way a screen flow usually does (from a Quick Action button etc) I appreciate the simple solution, this has been bugging me for a while.
    – bpunsky
    Commented Dec 11, 2023 at 20:23
  • to avoid the replacement page; you can use the button to set a controller property that is used in a rendered= apex:outputPanel that encloses the flow:interview. You'll need to use edit to show your code for us to offer more concrete advice. VF modals are certainly possible (they require CSS) but as VF is legacy, I wouldn't invest much time in VF modal approach
    – cropredy
    Commented Dec 11, 2023 at 21:02

0

You must log in to answer this question.

Browse other questions tagged .