Skip to content

Instantly share code, notes, and snippets.

@gitmatheus
Last active July 22, 2021 21:09
Show Gist options
  • Save gitmatheus/e959493d6a5507b235f8beb6ad01fe92 to your computer and use it in GitHub Desktop.
Save gitmatheus/e959493d6a5507b235f8beb6ad01fe92 to your computer and use it in GitHub Desktop.
Mock relationships in Apex - 03 of 05
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