![]() ERP Core API Developer Reference
|
fferpcore.DataSourceglobal abstract class DataSource The fferpcore.DataSource class is used to collate all of the fields required for a message and generate a query to obtain the values. It represents a list of input records for use with message generation. fferpcore.DataSource instances are used with the fferpcore.MessageDescriptionService to provide data from which to build messages. The service will use the fferpcore.MessageDescription to prepare the fferpcore.DataSource by asking it to require fields, lookups and one to many relationships. It will then query the fferpcore.DataSource and use the fferpcore.MessageDescription to generate the messages. Methods
requireFieldglobal virtual void requireField(SObjectField field) Ask that this data source to query the given field. This method will be called by the Declarative Publish framework or by custom message Nodes during the preparation phase of declarative message building. 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. // Given a datasource for Department__c, find the department name. departmentDataSource.requireField(Department__c.Name); requireLookupFieldglobal abstract fferpcore.DataSource requireLookupField(SObjectField field) Ask that this data source to query the given lookup. This method will be called by the Declarative Publish framework or by custom message Nodes during the preparation phase of declarative message building. Input Parameters
Return ValueA DataSource representing the target of the look up. 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 Worker__c that has a Department__c, find the department name. fferpcore.DataSource departmentDataSource = workerDataSource.requireLookupField(Worker__c.Department__c); departmentDataSource.requireField(Department__c.Name); requireOneToManyFieldglobal virtual fferpcore.DataSource requireOneToManyField(fferpcore.DataSource.BackReference backReference) Ask that this data source to query the given Master/Detail relationship. This method will be called by the Declarative Publish framework or by custom message Nodes during the preparation phase of declarative message building. Input Parameters
Return ValueA DataSource representing the target of the lookup. 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. fferpcore.DataSource employeeDataSource = departmentDataSource.requireOneToManyField( new fferpcore.DataSource.BackReference(Worker__c.SObjectType, Worker__c.Department__c) ); employeeDataSource.requireField(Worker__c.PayrollNumber__c); runQueryglobal abstract Iterator<fferpcore.DataSource.Row> runQuery() Load the data. This must only be performed on the top level DataSource, not any of the DataSources returned by the requireLookupField or requireOneToManyField methods. This method will be called by the Declarative Publish framework. Return ValueAn iterator of fferpcore.DataSource.Row objects containing the required data. 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.DataSource { 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 } } ExampleDataSource source = new ExampleDataSource(); source.requireField(Account.Name); source.requireField(Account.AccountNumber); Iterator<fferpcore.DataSource.Row> rows = source.runQuery(); //use rows to construct a message fferpcore.DataSource.Rowglobal abstract class Row A Row in the result set of the Data Source. Methods
getFieldValueglobal abstract Object getFieldValue(SObjectField field) Input Parameters
Return ValueThe value of the given field. If the field has not previously been requested, the behaviour of this method is not guaranteed. 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 abstract fferpcore.DataSource.Row getRelation(SObjectField field) Input Parameters
Return ValueA Row representing the requested object, or null if the lookup is null. If the field has not previously been requested, the behaviour of this method is not guaranteed. 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. } } getOneToManyglobal virtual Iterator<fferpcore.DataSource.Row> getOneToMany(fferpcore.DataSource.BackReference backReference) Input Parameters
Return ValueAn iterator of Rows representing the detail records for this master record. An empty iterator is returned if there are no detail rows. If the field has not previously been requested, the behaviour of this method is not guaranteed. 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. } fferpcore.DataSource.BackReferenceglobal virtual class BackReference How a Detail Object relates to its Master. Contains the Detail's ObjectType and the lookup field. Designed for use as a key in maps. This class is immutable. Methods
BackReferenceglobal BackReference(SObjectType detailObjectType, SObjectField detailToMasterLookupField) 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. // Given the Account and Contact objects... DataSource.BackReference backReference = new DataSource.BackReference(Contact, Contact.AccountId); // The detail object type and detail to master lookup field are as provided. System.assertEquals(Contact, backReference.getDetailObjectType()); System.assertEquals(Contact.AccountId, backReferene.getDetailToMasterLookupField()); // The master object is Account. The primary key field is Account.Id System.assertEquals(Account.Id, backReference.getPrimaryKeyField()); getDetailObjectTypeglobal SObjectType getDetailObjectType() Return ValueThe object type at the detail end of the link. See constructor for example use. getDetailToMasterLookupFieldglobal SObjectField getDetailToMasterLookupField() Return ValueThe field that the detail uses to reference its master. See constructor for example use. getPrimaryKeyFieldglobal virtual SObjectField getPrimaryKeyField() Return ValueThe primary key field on the Master side of the relationship. The field that the back reference points to. This will be the ID field on the master. See constructor for example use. equalsglobal virtual Boolean equals(Object other) Implementation of the Equals method. Returns true if 'other' is an identical BackReference. hashCodeglobal virtual Integer hashCode() Implementation of the hashCode() method allowing use as Map keys and Set values. Hash codes returned are only expected to be stable within one execution context and cannot be shared across execution contexts. This may impact any attempt to serialise a Map or Set containing BackReferences. |