Calling a Workflow from a Custom Button

I had a requirement to place a custom button on a layout that needed to call a workflow to accomplish some action.  This can’t be done natively but there is a neat little trick you can employ.

Workflows are triggered when specific field criteria is met.  With this in mind, we need to create a Javascript button that updates a checkbox field on the object.  I created a ‘toggle’ checkbox and set its default to unchecked.

I created a button to execute Javascript.  The code is straightforward: grab the object, check the checkbox, and update the object.  Some error handling will inform the user if the operation was successful or not.

The next step is to create a workflow rule that acts when my Generate Preview Toggle field is checked.  The workflow takes care of the task I need to accomplish, and then returns the toggle checkbox to unchecked. This is important, because otherwise the workflow cannot be initiated a second time from the button.

Remember to activate your workflow!

Author: Matt

Matthew is a highly accomplished and award-winning programmer who is well versed in a variety of the hottest technologies powering today's most successful companies. With 11+ years of experience, Matthew has done it all: from the most rudimentary tasks to complex implementations of entire applications, CRMs, and pieces thereof. Today he spends his time mastering salesforce.com administration, development, and implementation as he mediates between stakeholders and project owners to successfully interface a complex company in a complex industry.

Leave a Reply

Your email address will not be published. Required fields are marked *