Catch Those Errors

Whenever your application attempts to write data to the Force Platform database, there is a chance that an error can occur during the process. For instance, even if you have created an exquisitely perfect data interaction, someone else’s interaction with the underlying data might throw everything off.

For this reason, always include error handling code whenever your application writes to the database. This code gives you a way to handle the most difficult part of quality assurance for any application—the ability to fail (somewhat) gracefully.

9.
Modify the code in your save method to match the code below by adding the highlighted code:
public PageReference save() {
       if (PositionTypeID == 'other') {
       try{ newPositionType.Department__c ...

Get The Developer’s Guide to the Force.com Platform now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.