Book Image

Force.com Enterprise Architecture

By : Andrew Fawcett
Book Image

Force.com Enterprise Architecture

By: Andrew Fawcett

Overview of this book

Table of Contents (20 chapters)
Force.com Enterprise Architecture
Credits
Foreword
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Calling the Service layer


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;
}

Note

The constructor of these controllers is not shown, but it essentially stores StandardController or StandardSetController in a member variable for later...