Revenue Management API Developer Reference

ffrr.GroupingService

global with sharing class GroupingService

Class containing information regarding grouping source records.

Methods

create

global static ffrr.GroupingService.GroupingResult create(ffrr.GroupingService.GroupingContext context, ffrr.GroupingService.GroupingOptions options)

Creates Grouping Records from Staging Records for the Level 1 criteria provided. Specifying a Grouping RecordID will create Grouping records that relate to that grouping record.

Input Parameters

Name Type Description
context ffrr.GroupingService.GroupingContext Contains the information required to create grouping records such as which staging records to select using the Version ID.
options ffrr.GroupingService.GroupingOptions Specifies additional options for the create process such as the transaction type which determines whether a Synchronous, Asynchronous or Dynamic process is started.

Return Value

A GroupingResult object containing a list of IDs for created grouping records if a Synchronous process was run or a batch ID if an Asynchronous process ran.

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.

// Create new GroupingCriteria to configure which fields
// will be used to group the source records.

// Specify the level of the source records this grouping should apply to.
Integer level = 1;

// Specify the SObjectType of the source records to be grouped.
Schema.SObjectType objectType = Account.getSObjectType();

// Specify the fields that will be used for grouping.
List<Schema.SObjectField> objectFields = new List<Schema.SObjectField>();
objectFields.add(Account.Rating);

// Create the GroupingCriteria.
ffrr.GroupingService.GroupingCriteria criteria = new ffrr.GroupingService.GroupingCriteria(level, objectType, objectFields);


// Create a new GroupingContext
ffrr.GroupingService.GroupingContext context = new ffrr.GroupingService.GroupingContext();

// Add the GroupingCriteria
context.GroupingCriteria = new List<ffrr.GroupingService.GroupingCriteria>{criteria};

// set the VersionId or GroupingRecordIds
context.VersionId = [SELECT Id FROM ffrr__StagingVersion__c LIMIT 1].Id;
// Or
context.GroupingRecordIds = new List<Id>{[SELECT Id FROM ffrr__GroupingSummary__c LIMIT 1].Id};

// add the optional StagingSummary__c IDs and/or StagingDetail__c IDs that limit
// the creation of grouping records to only grouping these records
// If you set either StagingSummaryIds or StagingDetailIds to null, all relevant Summaries or Details will be selected.
// If set as a list, only relevant records within the list will be selected. An empty list will result in no Summaries or Details selected.
Map<Id, ffrr__StagingSummary__c> summariesById = new Map<Id, ffrr__StagingSummary__c>([SELECT Id FROM ffrr__StagingSummary__c LIMIT 100]);
context.StagingSummaryIds = new List<Id>(summariesById.keySet());
Map<Id, ffrr__StagingDetail__c> detailsById = new Map<Id, ffrr__StagingDetail__c>([SELECT Id FROM ffrr__StagingDetail__c LIMIT 100]);
context.StagingDetailIds = new List<Id>(detailsById.keySet());

// Create GroupingOptions
ffrr.GroupingService.GroupingOptions options = new ffrr.GroupingService.GroupingOptions();


// Create GroupingResult
ffrr.GroupingService.GroupingResult result = ffrr.GroupingService.create(context, options);

retrieve

global static List<ffrr.GroupingService.GroupingSummary> retrieve(Id groupingRecordId, Id versionId)

Retrieves the Grouping Summary records created from summary information in the Staging Table.
If only a valid version ID is provided with no Grouping Record ID, the top level Grouping Summary records related to this Staging Table version will be retrieved.
If both a Grouping Record ID and a Version ID is provided, any Grouping Summary records under the provided Grouping Summary record will be retrieved.

Input Parameters

Name Type Description
groupingRecordId Id The ID of the parent Grouping Summary record.
versionId Id The ID of a specific Staging Table version.

Return Value

A list of GroupingService.GroupingSummary records containing the grouping information.

deleteRecords

global static ffrr.GroupingService.DeleteResult deleteRecords(List<ffrr.GroupingService.DeleteCriteria> criteria, ffrr.GroupingService.DeleteOptions options)

Delete the Grouping data that matches the criteria within the given context. The TransactionType can be specified within the options.

Input Parameters

Name Type Description
criteria List<ffrr.GroupingService.DeleteCriteria> The delete criteria specifying what records to select for delete.
options ffrr.GroupingService.DeleteOptions The delete options specifying the transaction type.

Return Value

Delete result object containing the ID of the DeleteGroupingBatch, if one was started.

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.

// Obtain the ID of a user.
Id userId = [SELECT Id FROM User WHERE FirstName = 'Peter'][0].Id;

// Create a new delete context.
ffrr.StagingService.DeleteOptions options = new ffrr.StagingService.DeleteOptions();

// Specify the desired transaction type.
options.TransactionType = ffrr.CommonService.ApexTransactionType.Dynamic;

// Create criteria for the user.
ffrr.StagingService.DeleteCriteria criteria = new ffrr.StagingService.DeleteCriteria();
criteria.Users = new List<Id>{userId};

List<ffrr.StagingService.DeleteCriteria> criteriaList = new List<ffrr.StagingService.DeleteCriteria>{criteria};

// Invoke the method.
ffrr.StagingService.deleteRecords(criteriaList, options);

ffrr.GroupingService.GroupingContext

global class GroupingContext

Contains information from which to create Grouping 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.

// Create a new GroupingContext
ffrr.GroupingService.GroupingContext context = new ffrr.GroupingService.GroupingContext();

// set the VersionId or GroupingRecordIds
context.VersionId = [SELECT Id FROM ffrr__StagingVersion__c LIMIT 1].Id;
// Or
context.GroupingRecordIds = new List<Id>{[SELECT Id FROM ffrr__GroupingSummary__c LIMIT 1].Id};

// Add the GroupingCriteria
context.GroupingCriteria = new List<ffrr.GroupingService.GroupingCriteria>{
    new ffrr.GroupingService.GroupingCriteria(1, Account.getSObjectType(), new List<Schema.SObjectField>{Account.Rating})
};

// add the optional StagingSummary__c IDs and/or StagingDetail__c IDs that limit
// the creation of grouping records to only grouping these records.
// NOTE: If you set either StagingSummaryIds or StagingDetailIds to null, all relevant Summaries or Details will be selected.
// If set as a list, only relevant records within the list will be selected. An empty list will result in no Summaries or Details selected.
Map<Id, ffrr__StagingSummary__c> summariesById = new Map<Id, ffrr__StagingSummary__c>([SELECT Id FROM ffrr__StagingSummary__c LIMIT 100]);
context.StagingSummaryIds = new List<Id>(summariesById.keySet());

Map<Id, ffrr__StagingDetail__c> detailsById = new Map<Id, ffrr__StagingDetail__c>([SELECT Id FROM ffrr__StagingDetail__c LIMIT 100]);
context.StagingDetailIds = new List<Id>(detailsById.keySet());

Properties

Name Type Description
VersionId Id The ID of an existing StagingVersion__c to create primary groupings for.
GroupingRecordIds List<Id> The list of IDs of existing Grouping Records to create child groupings for. In this version the list must contain only one ID.
StagingSummaryIds List<Id> The list of the IDs of existing Staging Summaries that are to be grouped. Passing this as null will result in all relevant summaries being selected, regardless of the state of StagingDetailIds.
StagingDetailIds List<Id> The list of the IDs of existing Staging Details that are to be grouped. Passing this as null will result in all relevant details being selected, regardless of the state of StagingSummaryIds.
GroupingCriteria List<ffrr.GroupingService.GroupingCriteria> The list of GroupingService.GroupingCriteria used to create grouping records.

ffrr.GroupingService.GroupingOptions

global class GroupingOptions

Enables you to set options relating to grouping operations.

Properties

Name Type Description
TransactionType CommonService.ApexTransactionType Specifies the Apex process to use.

Methods

GroupingOptions

global GroupingOptions()

ffrr.GroupingService.GroupingResult

global class GroupingResult

Container for data resulting from a Grouping operation.

Properties

Name Type Description
BatchId Id ID of a batch job if one was created.
GroupingRecordIds List<Id> IDs of created GroupingRecords.

ffrr.GroupingService.DeleteCriteria

global class DeleteCriteria

Criteria to select which records are deleted within a delete operation.

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.

// Create a criteria.
ffrr.GroupingService.DeleteCriteria criteria = new ffrr.GroupingService.DeleteCriteria();

// Obtain the ID of the current user
Id userId = UserInfo.getUserId();

// Set the user parameter on the criteria. This can be any list of User IDs.
// If specified, it will only delete records belonging to those users.
criteria.Users = new List<Id>{userId};

// Obtain a list of versions to delete.
Map<Id, ffrr__StagingVersion__c> versionsById = new Map<Id, ffrr__StagingVersion__c>(
    [SELECT Id FROM ffrr__StagingVersion__c LIMIT 5]
);
criteria.Versions = new List<Id>(versionsById.keySet());

// Only delete versions where ffrr__IsLatest__c is false.
criteria.KeepLatestVersions = true;

Properties

Name Type Description
Users List<Id> Specify which Users' grouping records will be deleted. All Users' grouping records will be deleted if this is left empty.
Versions List<Id> Specify the versions for which related grouping records will be deleted.
KeepLatestVersions Boolean Determines if the grouping data of the latest versions will be deleted.

Methods

DeleteCriteria

global DeleteCriteria()

ffrr.GroupingService.DeleteOptions

global class DeleteOptions

Options to influence how a delete operation is performed.

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.

// Create new delete options.
ffrr.GroupingService.DeleteOptions options = new ffrr.GroupingService.DeleteOptions();

// Specify the desired transaction type.
options.TransactionType = ffrr.CommonService.ApexTransactionType.DYNAMIC;

Properties

Name Type Description
TransactionType CommonService.ApexTransactionType How the transaction should be executed.

Methods

DeleteOptions

global DeleteOptions()

ffrr.GroupingService.DeleteResult

global class DeleteResult

Container for data resulting from a delete operation.

Properties

Name Type Description
BatchId Id Id of the ASyncApexJob if one was created.

ffrr.GroupingService.GroupingSummary

global class GroupingSummary

Contains the information of a Grouping Summary record.

Properties

Name Type Description
Id Id The ID of the Grouping Summary record.
ParentGroupingId Id The ID of the parent GroupingSummary record. For the GroupingSummary at the top level the ID is null.
VersionId Id The ID of the Version record associated with this GroupingSummary record.
BatchTrackingControlId Id The ID of the BatchTrackingControl record associated with this GroupingSummary record.
SObjectType Schema.SObjectType The object type of the source record this grouping applies to.
SObjectField Schema.SObjectField The object field of the source record this grouping applies to.
Order Integer The position of this Grouping Summary relative to the Grouping Summary at the highest level.
IsExpandable Boolean A Grouping Summary is expandable if child groupings can be created for it.
Expanded Boolean A Grouping Summary is expanded if Create has been run on it.
Value Object The value of the grouped field.
TotalCost Decimal The summed Total Cost of the grouped records.
TotalRevenue Decimal The summed Total Revenue of the grouped records.
PreviouslyAmortized Decimal The summed Previously Amortized amount of the grouped records.
PreviouslyRecognized Decimal The summed Previously Recognized amount of the grouped records.
ToAmortizeThisPeriod Decimal The summed To Amortize This Period amount of the grouped records.
ToRecognizeThisPeriod Decimal The summed To Recognize This Period amount of the grouped records.
TotalLeafRecordCount Integer The total number of the leaf details under this grouping.

ffrr.GroupingService.GroupingCriteria

global class GroupingCriteria

Contains the criteria related to grouping from staging records.

Properties

Name Type Description
Level Integer The level of source records this grouping should apply to.
SObjectType Schema.SObjecttype The object type of source records to be grouped.
SObjectFields List<Schema.SObjectField> The fields that will be used for grouping.

Methods

GroupingCriteria

global GroupingCriteria()

GroupingCriteria

global GroupingCriteria(Integer level, Schema.SObjectType SObjectType, List<Schema.SObjectField> SObjectFields)

© Copyright 2009–2018 FinancialForce.com, inc. Confidential – all rights reserved. Various trademarks held by their respective owners.