Using the Service layer and database access

As with the Visualforce Apex controller action methods you've seen in the earlier chapters, the Service layer is also designed to be called from Visualforce JavaScript Remoting methods, as follows:

public with sharing class RaceResultsController {
  @RemoteAction
  public static List<RaceService.ProvisionalResult>loadProvisionalResults(Id raceId) {
    return RaceService.calculateProvisionResults(
      new Set<Id>{ raceId }).get(raceId);
  }
}

To make Lightning Component controller server-side calls to Apex use the @AuraEnabled annotation method:

public with sharing class RaceResultsController { @AuraEnabled public static List<RaceService.ProvisionalResult>loadProvisionalResults(Id raceId) { return RaceService.calculateProvisionResults( ...

Get Force.com Enterprise Architecture - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.