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( new Set<Id>{ raceId }).get(raceId); }
You will also need to apply the @AuraEnabled
method to accessors for Apex types referenced by the Controller methods:
public class ProvisionalResult...