,

Saving the Position Record

Now, did you forget anything? Oh yes, you still have to save the Position__c record, the main focus of the page.

You don’t want to do anything extraordinary with this record—simply take the standard actions to save the record. You can simply call the default save action for the standard controller to accomplish this task.

Except for one little problem. Remember, the save method in your extension overrides the save method for the standard controller. If you call the default save method, you find your code in an endless loop.

You can escape this problem by declaring another instance of the standard controller and then calling the save method on that instance.

7.
Add the following code to the beginning of your class

private final ApexPages.standardController theController;

8.
Add the highlighted line of code to your save method –

public PageReference save() {
  if (PositionTypeID == 'other') {
       newPositionType.Department__c =
        position.Department__c;
       insert newPositionType;
       position.Position_Type__c = newPostionType.ID;
       }
  else {
    Position.Position_Type__c = positionTypeID;
    }
  return theController.save();
}

This final line calls the save method on the new instance of the controller, which saves the current record and returns a PageReference, which is, in turn, returned to the calling page.

You have completed all of the proactive work for the new feature of your Force Platform application, but you still have to enable your application to react to any unexpected problems that might arise.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.255.24