We have a custom button that came with the installation of a managed package. We are using this custom button on a page layout to open a new page with a PDF. We want to display an error message when the user clicks on this button and one of the custom fields is blank, prompting users to add a value to the field first.

We can't make the field required as there are other business functionalities that depend on it, so the field must remain non-required.

I understand that validation rules are only applicable when a DML operation occurs, but is there a way to achieve this? Also, since this field is part of a managed package, I can't edit it to make it "execute JavaScript."

Any help would be appreciated. Thanks.

  • Why not add a small screen flow that warns user the PDF function not available until field is entered (add the screen flow component to your lightning record page)
    – cropredy
    Aug 29 at 21:53
  • @cropredy The screen flow would display a message if the custom field is blank, indeed. However, it still does not prevent the user from clicking the button in the 'Highlights Panel'.
    – Alp
    Aug 29 at 22:57
  • Is the button a Quick Action on the page layout? If so, you could use dynamic actions to hide the button completely to remove it from the page until the required information is populated, probably alongside cropredy's comment around using a flow to provide some guidance to the users. Aug 30 at 2:54
  • @CallumMacErlich That is one possible way to do it, but they prefer showing an error message over hiding it completely.
    – Alp
    Aug 30 at 3:38
  • 2
    given the above, the only way I see of doing this is by removing the button and replacing with a LWC, VF, or screen flow that does the check, displays error if failed, otherwise, redirects to whatever the custom button initiates
    – cropredy
    Aug 30 at 17:30


You must log in to answer this question.