fferpcore.DataSourceBaseglobal with sharing abstract class DataSourceBase extends DataSource Base support for DataSource, specifically handling relations. This class extends fferpcore.DataSource Methods
DataSourceBaseglobal DataSourceBase(SObjectType objectType) Input Parameters
getSObjectTypeglobal virtual SObjectType getSObjectType() Return ValueThe object type that this data source queries. requireLookupFieldglobal virtual override fferpcore.DataSource requireLookupField(SObjectField field) Implements requireLookupField from the fferpcore.DataSource interface. Input Parameters
Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. public class MyDataSource extends fferpcore.DataSourceBase { //Doesn't override requireLookupField // ... } // Given a Worker__c that has a Department__c, find the department name. MyDataSource workerDataSource = createWorkerDataSource(); //Make a MyDataSource object. fferpcore.DataSource departmentDataSource = workerDataSource.requireLookupField(Worker__c.Department__c); departmentDataSource.requireField(Department__c.Name); requireLookupFieldglobal virtual override fferpcore.DataSource requireLookupField(String fieldName) Implements requireLookupField from the fferpcore.DataSource interface. Input Parameters
Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. public class MyDataSource extends fferpcore.DataSourceBase { //Doesn't override requireLookupField // ... } // Given a Worker__c that has a Department__c, find the department name. MyDataSource workerDataSource = createWorkerDataSource(); //Make a MyDataSource object. fferpcore.DataSource departmentDataSource = workerDataSource.requireLookupField(Worker__c.Department__c); departmentDataSource.requireField(Department__c.Name); requireOneToManyFieldglobal virtual override fferpcore.DataSource requireOneToManyField(fferpcore.DataSource.BackReference backReference) Implements requireOneToManyField from the fferpcore.DataSource interface. Input Parameters
Return ValueAn fferpcore.DataSource for the related records. Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. public class MyDataSource extends fferpcore.DataSourceBase { //Doesn't override requireOneToManyField // ... } // Given a Department__c, find the Worker__c in and then the payroll number. MyDataSource departmentDataSource = createDepartmentDataSource(); //Make a MyDataSource object. fferpcore.DataSource workerDataSource = departmentDataSource.requireOneToManyField(new fferpcore.DataSource.BackReference(Worker__c, Worker__c.Department__c)); workerDataSource.requireField(Worker__c.PayrollNumber__c); requireFieldglobal virtual override void requireField(String fieldName) Implementation of requireField which parses the supplied fieldName using parseFieldName(). runQueryglobal virtual override Iterator<fferpcore.DataSource.Row> runQuery() Implements runQuery from the fferpcore.DataSource interface. Return ValueAn instance of fferpcore.DataSource.Row objects. Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. public class ExampleDataSource extends fferpcore.DataSourceBase { private Set<SObjectField> m_fields; public ExampleDataSource() { } public override void requireField(SObjectField field) { m_fields.add(field); } public override Iterator<fferpcore.DataSource.Row> runQuery() { // Run SOQL to retrieve the data in m_fields and related records. } } parseFieldNameglobal virtual SObjectField parseFieldName(String spec) Determines the object field from the field specification provided. Input Parameters
fferpcore.DataSourceBase.RelatedDataSourceglobal interface RelatedDataSource Contract with data sources created for lookups. DataSources may implement this interface directly, or an Adapter Pattern may be used to connect the related DataSource. Methods
asDataSourceDataSource asDataSource() Return this datasource as an instance of DataSource. In most cases implementors will implement both interfaces and return themselves from this method, though the returned fferpcore.DataSource does not have to be the same instance as the RelatedDataSource. runLookupQueryRelatedQueryResult runLookupQuery(SObjectField lookupField, fferpcore.DataSourceBase.DirectQueryResult source) Perform the query given the set of foreign keys from the parent DataSource. Input Parameters
fferpcore.DataSourceBase.RelatedQueryResultglobal interface RelatedQueryResult The result from calling runLookupQuery on a RelatedDataSource. MethodsgetRelatedRowDataSource.Row getRelatedRow(SObjectField lookupField, fferpcore.DataSource.Row parentRow) Return the row corresponding to the given key. Input Parameters
Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. public class ExampleRelatedQueryResult implements fferpcore.DataSourceBase.RelatedQueryResult { private Map<Id, fferpcore.DataSource.Row> m_rowsById; //... Has a constructor. public DataSource.Row getRelatedRow(SObjectField lookupField, fferpcore.DataSource.Row parentRow) { return m_rowsById.get( (Id) parentRow.getFieldValue(lookupField) ); } } fferpcore.DataSourceBase.OneToManyRelatedDataSourceglobal interface OneToManyRelatedDataSource Contract with data sources acting as one-to-many relationships with this DataSource. DataSources may implement this interface directly, or an Adapter Pattern may be used to connect the related DataSource. Methods
asDataSourceDataSource asDataSource() Return this datasource as an instance of DataSource. In most cases implementors will implement both interfaces and return themselves from this method, though the returned fferpcore.DataSource does not have to be the same instance as the OneToManyRelatedDataSource. runOneToManyQueryOneToManyQueryResult runOneToManyQuery(fferpcore.DataSource.BackReference backReference, fferpcore.DataSourceBase.DirectQueryResult parentSource) Perform the query given the set of foreign keys from the parent DataSource. Input Parameters
fferpcore.DataSourceBase.OneToManyQueryResultglobal interface OneToManyQueryResult Query result from an OneToManyRelatedDataSource. MethodsgetOneToManyResultIterator<DataSource.Row> getOneToManyResult(fferpcore.DataSource.BackReference backReference, fferpcore.DataSource.Row masterRow) Return the rows corresponding to the given BackReference on the given Master Row. Input Parameters
Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. public class ExampleOneToManyQueryResult implements fferpcore.DataSourceBase.OneToManyQueryResult { private final Map<Id, List<fferpcore.DataSource.Row>> m_rowsByForeignKey; // ... has a constructor /** * Return the rows corresponding to the given key. */ public Iterator<fferpcore.DataSource.Row> getOneToManyResult(fferpcore.DataSource.BackReference backReference, fferpcore.DataSource.Row masterRow) { SObjectField parentPrimaryKeyField = backReference.getPrimaryKeyField(); Id masterPrimaryKey = (Id) masterRow.getFieldValue(parentPrimaryKeyField); List<fferpcore.DataSource.Row> rows = m_rowsByForeignKey.get(masterPrimaryKey); return rows != null ? rows.iterator() : new List<fferpcore.DataSource.Row>().iterator(); } } fferpcore.DataSourceBase.DirectQueryResultglobal interface DirectQueryResult Means by which the queryRelatedDataSources method can access keys to query by. MethodsgetPrimaryKeysSet<Id> getPrimaryKeys() Used by the default implementation of OneToManyRelatedDataSource to find the set of what to it are foreign keys to look up. Return ValueThe set of primary keys for all records in this source not including null. These are the foreign keys in the one to many related DataSource. getKeysForFieldSet<Id> getKeysForField(SObjectField field) Used by the default implementation of RelatedDataSource to find the set of keys to query for. Input Parameters
Return ValueThe set of keys, not including null, for the given field. fferpcore.DataSourceBase.SimpleDirectQueryResultglobal inherited sharing class SimpleDirectQueryResult implements DirectQueryResult An implementation of DirectQueryResult encapsulates a list of SObject records. This class implements the following interfaces: Methods
SimpleDirectQueryResultglobal SimpleDirectQueryResult(List<SObject> records) Input Parameters
getRecordsglobal List<SObject> getRecords() Return ValueThe list of records in this result. Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. public void checkGetRecords(List<SObject> records) { fferpcore.DataSourceBase.DirectQueryResult directResult = new fferpcore.DataSourceBase.SimpleDirectQueryResult(records); List<SObjects> moreRecords = directResult.getRecords(); System.assertEquals(records, moreRecords); } getPrimaryKeysglobal Set<Id> getPrimaryKeys() Return ValueThe set of IDs, not including null, for all records in this source. Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. public checkAccountKeys(Set<Id> idsToQuery) { List<Account> accounts = [SELECT Id, AccountNumber, BillingCity WHERE Id IN :idsToQuery] fferpcore.DataSourceBase.DirectQueryResult directResult = new fferpcore.DataSourceBase.SimpleDirectQueryResult(accounts); Set<Id> moreIds = directResult.getPrimaryKeys(); System.assertEquals(idsToQuery, moreIds); } getKeysForFieldglobal Set<Id> getKeysForField(SObjectField field) Input Parameters
Return ValueThe set of keys, not including null, for the given field. Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. //Get some workers, then find all their departments. List<Worker__c> workers = [SELECT Id, Name, Department__c FROM Worker__c]; fferpcore.DataSourceBase.SimpleDirectQueryResult simpleResult = new fferpcore.DataSourceBase.SimpleDirectQueryResult(workers); Set<Id> departmentIds = simpleResult.getKeysForField(Worker__c.Department__c); //You now have all the department Ids for all your workers. You can now go ahead and run soql //to retrieve their email addresses, and email them all to tell them how great their staff are. fferpcore.DataSourceBase.Rowglobal inherited sharing class Row extends DataSource.Row Implementation of the fferpcore.DataSource.Row abstract class. Represents the result of reading a Row from the database. This class extends fferpcore.DataSource.Row Methods
Rowglobal Row(SObject record, Map<SObjectField, fferpcore.DataSourceBase.RelatedQueryResult> relatedResults, Map<fferpcore.DataSource.BackReference, fferpcore.DataSourceBase.OneToManyQueryResult> oneToManyResults) Input Parameters
getFieldValueglobal override Object getFieldValue(SObjectField field) Implementation of getFieldValue(field) on DataSource.Row. Input Parameters
Return ValueThe value of the requested field. May give an exception if the field was not queried. Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. trigger ExampleTrigger on Order (before insert) { fferpcore.TriggerDataSource source = new fferpcore.TriggerDataSource(Records); fferpcore.DataSource userDataSource = source.requireField(Order.CreatedBy); userDataSource.requireField(User.Email); Iterator<fferpcore.DataSource.Row> dataSourceRowIterator = source.runQuery(); // runQuery should call runQuery on related data sources. E.g. on userDataSource while(dataSourceRowIterator.hasNext()) { fferpcore.DataSource.Row orderSourceRow = dataSourceRowIterator.next(); fferpcore.DataSource.Row userSourceRow = orderSourceRow.getRelation(Order.CreatedBy); String createdByEmail = userSourceRow.getField(User.Email); //Create and send a message with the email in it. } } getFieldValueglobal virtual override Object getFieldValue(String fieldName) Implementation of getFieldValue(field) on DataSource.Row. Input Parameters
Return ValueThe value of the requested field. An exception might occur if the field was not queried. Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. trigger ExampleTrigger on Order (before insert) { fferpcore.TriggerDataSource source = new fferpcore.TriggerDataSource(Records); fferpcore.DataSource userDataSource = source.requireField(Order.CreatedBy); userDataSource.requireField(User.Email); Iterator<fferpcore.DataSource.Row> dataSourceRowIterator = source.runQuery(); // runQuery should call runQuery on related data sources. E.g. on userDataSource while(dataSourceRowIterator.hasNext()) { fferpcore.DataSource.Row orderSourceRow = dataSourceRowIterator.next(); fferpcore.DataSource.Row userSourceRow = orderSourceRow.getRelation(Order.CreatedBy); String createdByEmail = userSourceRow.getField(User.Email); //Create and send a message with the email in it. } } getRelationglobal override fferpcore.DataSource.Row getRelation(SObjectField field) Implementation of getRelation(field) on DataSource.Row. Input Parameters
Return ValueThe DataSource.Row that represents the given relation. Returns null if the relation is missing or was not queried. Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. trigger ExampleTrigger on Order (before insert) { fferpcore.TriggerDataSource source = new fferpcore.TriggerDataSource(Records); fferpcore.DataSource userDataSource = source.requireField(Order.CreatedBy); userDataSource.requireField(User.Email); Iterator<fferpcore.DataSource.Row> dataSourceRowIterator = source.runQuery(); // runQuery should call runQuery on related data sources. E.g. on userDataSource while(dataSourceRowIterator.hasNext()) { fferpcore.DataSource.Row orderSourceRow = dataSourceRowIterator.next(); fferpcore.DataSource.Row userSourceRow = orderSourceRow.getRelation(Order.CreatedBy); String createdByEmail = userSourceRow.getField(User.Email); //Create and send a message with the email in it. } } getRelationglobal virtual override fferpcore.DataSource.Row getRelation(String fieldName) Implementation of getRelation(fieldName) on DataSource.Row. Input Parameters
Return ValueThe DataSource.Row that represents the given relation. Returns null if the relation is missing or was not queried. getOneToManyglobal override Iterator<fferpcore.DataSource.Row> getOneToMany(fferpcore.DataSource.BackReference backRef) Implementation of getOneToMany(backRef) on DataSource.Row. Return an Iterator of fferpcore.DataSource.Row that represent the given one to many relationship. Returns an empty Iterator if the relationship has no related Rows or was not queried. Input Parameters
Return ValueAn iterator of Row objects. Sample Code//Note: This sample code is for demonstration purposes only. It is not intended for //use in a production environment, is not guaranteed against defects or errors, and //is in no way optimized or streamlined. // Given a Deparment__c find the Employee payroll numbers. new fferpcore.DataSource.BackReference workerDepartmentBackRef = new new fferpcore.DataSource.BackReference(Worker__c.SObjectType, Worker__c.Department__c); fferpcore.DataSource employeeDataSource = departmentDataSource.requireOneToManyField(workerDepartmentBackRef); employeeDataSource.requireField(Worker__c.PayrollNumber__c); Iterator<fferpcore.DataSource.Row> departmentRows = departmentDataSource.runQuery(); while(departmentRows.hasNext()) { fferpcore.DataSource.Row departmentRow = departmentRows.next(); Iterator<fferpcore.DataSource.Row> workerRows = departmentRow.getOneToMany(workerDepartmentBackRef); //Do something with all the workers in this department. } parseFieldNameglobal virtual SObjectField parseFieldName(String spec) Determines the contract for the string based field accessor methods. Accepts either a single field name or the combination objectType.fieldName as used by the fferpcore.Path class. |