The preceding examples have shown the use of the service class methods from Visualforce Controller methods. Let's take a closer look at what is happening here, the assumptions being made, and also at an Apex Scheduler example. Other examples of service methods in action will feature throughout later chapters.
The following code represents code from a controller class utilizing StandardController
that provides support for the Visualforce page associated with a Custom Button on the Race
object. Notice how it wraps the record ID in Set
, honoring the bulkified method signature:
public PageReference awardPoints() { try { RaceService.awardChampionshipPoints( new Set<Id> { standardController.getId() }); } catch (Exception e) { ApexPages.addMessages(e); } return null; }