I have a APEX Class that runs from a button on a standard record page. It creates a related record in another table. The code works fine as it is now.
But I want to add a feature that does a check (Selection Field == Value) and if the check fails the user is given a custom message and the code stops running, and no record gets created. I can't figure this out.
I have run across such functions as 'adderror' and 'addmessages', but not sure how to get these working. This starts from a button press on the starting page, the record is created and then the user is taken to the records page. If there is no record to be created then there is no page to go to. Can I put the error message back onto the starting page? But would it not need to be refreshed to show the error, and then won't the error status be lost? Or do I need to create a new VF page that is just a spot holder for the error? If error, then VF page and show error, if not then normal process? I was hoping I could do a simple 'alert', but that doesn't work.
Any pointers would help here, not sure what I need to do to get this working.