Skip to Main Content


Apex: Select a validation rejected field via .js

User_R64LRAug 16 2022 — edited Aug 16 2022

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:
Submit (sequence 10)
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:
Can the JS execute after validation?
Is there a built in list of elements that can be accessed that failed validation?
Is validation tied directly to submitting? If so, why does the item-error class not get added until after it fails?
What is the order of execution after submitting a page?

Post Details
Added on Aug 16 2022
1 comment