I'm on day 3 of my SalesForce development journey, what a cool platform, I'm having a blast.
I hope I'm saying this correctly: we'd like to apply a data object validation rule on a picklist.
Here's a screenshot of my rule. We need to prevent users from not picking a value from the Cancellation Reason - Cancellation_Reason__c
picklist. This is the rule:
ISPICKVAL(Cancellation_Reason__c, "")
I'm pretty confident that my rule is correct, but this being day 3...
On update, I'm throwing the following exception, and it's happen when I'd expect a pretty validation failure message somewhere around the field. Of course, the value isn't saving correctly, but I'd like to for the save to abort and our validation message to be displayed somewhere on the screen.
12:48:55.231 (231827662)|USER_DEBUG|[48]|DEBUG|Update failed. First exception on row 0 with id 006c0000008hVyNAAU; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Please enter a cancellation reason: [Cancellation_Reason__c]
This is the code that's creating the misbehavior and log messages
public PageReference updateEnrollment() {
System.Debug('---------------- updateEnrollment() requested');
try {
update this.opportunity;
} catch(Exception e) {
System.Debug('attempting to SDENrollmentsController.updateEnrollment(), but throwing an exception on update this.opportunity;');
System.Debug(e.getMessage());
}
// update this.opportunity;
PageReference retVal = null;
retVal = Page.SDAccountOverview;
retVal.getParameters().put('id', this.curAccount.Id);
retVal.setRedirect(true);
return retVal;
}
When I remove the try/catch, the screen doesn't error out, but potentially worse, it appears to the user that the save occurs (and the exception message gets moved in to the logs). Here's what I see on the screen when I pull the try/catch: screenshot of ugly error page.
It would be awfully nice to apply this validation rule w/o a swallowed exception or an ugly error page.
Thank you for looking.