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
Jason Kuzmak 12Jason Kuzmak 12 

Can I create conditional VisualForce prompts?

I may have promised my boss more than I can deliver, but hopefully you all can help me with something. I created a VisualForce form with "soft-required" fields, which are marked with a red asterisk, and do not prevent the user from saving the record if they are not filled out. This way our field salesmen can start a form, save it, but complete it later. They won't be able to submit for approval unless all those fields are filled, thanks to an additional formula field that doesn't checkmark itself unless all soft-required fields are filled out. 

This part works great, but here's where I'm running into trouble. What I would love to do for our dear team (who have been waiting for this feature for so long) is help them with an additional prompt that says:
"Are you sure you'd like to save this form? Looks like you still have some fields to fill before this is ready to submit."

...What if they don't, though?
Based on what I've seen, I can only add a prompt directly to my button action, and not include it conditionally if such-and-such is true.
Can anyone point me in the right direction?

Best Answer chosen by Jason Kuzmak 12
Tuan LuTuan Lu
There is no lockerservice in VF so you can do pretty much anything you want in javascript onload, onclick, onFocus etc. A prompt can be created with a outputPanel and some CSS, or even just a window.alert function.

All Answers

Tuan LuTuan Lu
I dont think you actually need to create a VF page for this. It could be easier to change the recordType/pageLayout based on a status field. Also you can have a validation rule on formula field that checks the value of your soft-required fields.
Jason Kuzmak 12Jason Kuzmak 12

Hi Tuan,

Validation rules would prevent saving, and thus end up not being soft-required. As for the layout/record type idea, actually, that was my original plan. I changed the field labels to not be required and simply start with asterisks, however, they are not very visible (color-coding them in VisualForce is excellent for guys that like to skim pages). Also, some fields are required on certain record types and not on others, so the asterisks end up spilling over into the wrong record type (the solution being that I have to create multiples of the same field). Even if this were a good fit as a solution, this would only be viable if I had some way of collecting the field names that still need to be filled in and customizing the "cannot find a proper approval process" message to list those fields, but no customization on that message is possible from what I've read. The relationship between our sales team and Salesforce is tenuous, so the ideal user experience must come first, in this case. A prompt, if possible, is what I need. 

Tuan LuTuan Lu
There is no lockerservice in VF so you can do pretty much anything you want in javascript onload, onclick, onFocus etc. A prompt can be created with a outputPanel and some CSS, or even just a window.alert function.
This was selected as the best answer
Jason Kuzmak 12Jason Kuzmak 12
Great, I will look into the window.alert function. Thanks