Last active
July 22, 2021 21:09
-
-
Save gitmatheus/e959493d6a5507b235f8beb6ad01fe92 to your computer and use it in GitHub Desktop.
Mock relationships in Apex - 03 of 05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class DataLayerHandler { | |
| // First, create the dataLayer variable: | |
| private IDataLayer dataLayer; | |
| // For an empty constructor, you create a new instance of the DataLayer: | |
| public DataLayerHandler() { | |
| this(new DataLayer()); | |
| } | |
| // If the constructor contains a dataLayer as a parameter, use it in your class. | |
| public DataLayerHandler(IDataLayer dataLayer) { | |
| this.dataLayer = dataLayer; | |
| } | |
| // Here, you can access the data using the DataLayer: | |
| public void proccessDocuments() { | |
| List<Document__c> documentsToProcess = dataLayer.getDocumentList(); | |
| } | |
| public class DataLayer implements IDataLayer { | |
| List<Document__c> getDocumentList(){ | |
| return [SELECT Id, Account__r.Business__c FROM Document__c]; | |
| } | |
| } | |
| public interface IDataLayer { | |
| List<Document__c> getDocumentList(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment