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, such as from a Lightning Component, 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 PageReferenceawardPoints(){ try{ RaceService.awardChampionshipPoints(new Set<Id> {standardController.getId() }); } catch (Exception e){ ApexPages.addMessages(e); } return null; }
The constructor of these controllers is not shown, but it essentially stores StandardController
or StandardSetController
in a member variable for later...