function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
phiberoptikphiberoptik 

Custom JavaScript Button to Edit and Save a Record instantly

The end goal is to fire a validation rule without a user having to click Edit and then Save. The action is to "validate" that the record is ready to be submitted for approval. Since I cannot invoke a validation rule through the Submit for Approval button being pressed, I would like for the end users to be able to click a "Validate" button that will edit and save a record in order to check validation. If they invoke the rule, they know they are not ready to submit it and they receive the error message informing them of the fields they are missing. If they dont receive the message, they know they are ready to submit it for approval.

Thanks in Advance.
Marty C.Marty C.

Hello, phiberoptik, I think you can do this using the AJAX Toolkit[1] and a custom button configured for "Execute JavaScript". For a button (like this sample Account button[2]) to work, I think you need to add a checkbox field that will set off the validation rule. This checkbox field doesn't have to be displayed to the user, so a user wouldn't even need to know it exists.

The general idea is:

  1. Send an Ajax request using JavaScript to update the current record, setting the validation checkbox to true
  2. Examine the result to determine whether validation succeeded, and share the result with the user


It would be best to also set up a workflow rule that will automatically clear the validation checkbox every time it is set. This should be fine because workflow rules fire after validation rules in the order of execution[3].

[1]: AJAX Toolkit (http://www.salesforce.com/us/developer/docs/ajax/)
[2]: sample Account button (http://pastebin.com/wrm8Gevw)
[3]: order of execution (http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_order_of_execution.htm)