Forum Stats

  • 3,874,997 Users
  • 2,266,791 Discussions


Apex: Select a validation rejected field via .js

User_R64LR Member Posts: 1 Green Ribbon
edited Aug 16, 2022 4:46PM in APEX Discussions

I am attempting to select a "value required" field via JavaScript on the event that it provides an error on submitting. The ultimate goal is to add a font awesome character to a collapsed region on a large form to give the user a visual as to what area still needs filled or is filled incorrectly.

The current (non) solution I attempted was having a button with a dynamic action in 2 parts:

  1. Submit (sequence 10)
  2. Exec JS Code (Sequence 20)

The JS is attempting to get all elements with the error class name added after the validation fails.

console.log("Error element test triggered");

const errorElements = document.getElementsByClassName("apex-page-item-error");

if(errorElements.length > 0)(



On the first button click I can see the submit, js exec, then the console.log saying it's been triggered. On the second, it has the same result with the HTMLCollection added. To me this indicated that either validation doesn't occur until all of the dynamic actions are complete or the classes aren't added until after all of the dynamic actions are complete.

Given this, I have a few questions:

  1. Can the JS execute after validation?
  2. Is there a built in list of elements that can be accessed that failed validation?
  3. Is validation tied directly to submitting? If so, why does the item-error class not get added until after it fails?
  4. What is the order of execution after submitting a page?


  • InoL
    InoL Member Posts: 10,209 Blue Diamond

    Submit (sequence 10)

    Exec JS Code (Sequence 20)

    You cannot have a DA after a submit. When submitting the page you are leaving the page, so anything after the submit is never executed.

    A page has a Reload on Submit property:

    Select when the page should be reloaded following a page submission.

    Available options include:


    Always reload the page to display errors and the success message.

    Only for Success

    Show errors dynamically without reloading page, but reload it after a successful processing.

    If you set it to Always, you can have an On Load DA that checks if there is an error message displayed.

    "Value required" is another thing. It can be evaluated before submit by the browser (and APEX too for security). Sometimes we turn this property off and add a Not Null validation. This gives a better UI, because it behaves like any other APEX validation.