Code to run a table mass action from a button?

  • 1
  • Question
  • Updated 1 month ago
  • Answered
Hi,

I have a mass action that when all of the rows on a table are selecting pops up and can be run.

Does anyone know if we can create a button that selects all then runs that mass action?

I assume javascript can do it but not sure where to start
Photo of David Forder

David Forder

  • 2,380 Points 2k badge 2x thumb

Posted 1 month ago

  • 1
Photo of Matt Davis

Matt Davis, Employee

  • 800 Points 500 badge 2x thumb
Just to make sure I understand, are you trying to run an action across all the rows in a model?
Photo of David Forder

David Forder

  • 2,380 Points 2k badge 2x thumb
Yes. I can add as a mass action on the table (and have).. just wanted to attach it to a separate button

Photo of Matt Davis

Matt Davis, Employee

  • 800 Points 500 badge 2x thumb
What does the action do?
Photo of David Forder

David Forder

  • 2,380 Points 2k badge 2x thumb
triggers a salesforce flow

Photo of Matt Davis

Matt Davis, Employee

  • 800 Points 500 badge 2x thumb
Did you want the button to only run the action on the rows the user has selected, or does it assume they want to run it on all the rows in the model?
Photo of David Forder

David Forder

  • 2,380 Points 2k badge 2x thumb
all rows on model be good
Photo of Matt Davis

Matt Davis, Employee

  • 800 Points 500 badge 2x thumb
Sweet, that's actually easier to do than trying to figure out what the user had selected. The design is something like this:

  1. On your Model, add a UI only checkbox (I'll just refer to this as UI_Check)
  2. On your Model, add an action When row in model is updated. For the updated field select UI_Check. 
  3. In that model action, add the Data Source action.
  4. On your Button, add an action that Updates a field on a row. Select your Model and the field UICheck, and have it update all rows in the model.
That should do the job, however it'll only work once since the second try it'll be trying to check a box that's already checked. So on your button you will probably need to add a Branch so that it checks UI_Check if its unchecked, and unchecks it if it is already checked.
Photo of David Forder

David Forder

  • 2,380 Points 2k badge 2x thumb
Fantastic work around!

Thanks Matt
Photo of Matt Davis

Matt Davis, Employee

  • 800 Points 500 badge 2x thumb
No problem, hope it works out