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);

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' LIMIT 1].Id;

ffrr.GroupingService.DeleteOptions options = new ffrr.GroupingService.DeleteOptions();

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

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

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

// Invoke the method.
ffrr.GroupingService.deleteRecords(criteriaList, 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.

ffrr.GroupingService.DeleteCriteria

global with sharing 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
KeepLatestVersions Boolean Determines if the grouping data of the latest versions will be deleted.
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.

Methods

DeleteCriteria

global DeleteCriteria()

ffrr.GroupingService.DeleteOptions

global with sharing 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 ffrr.CommonService.ApexTransactionType How the transaction should be executed.

Methods

DeleteOptions

global DeleteOptions()

ffrr.GroupingService.DeleteResult

global with sharing class DeleteResult

Container for data resulting from a delete operation.

Properties

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

Methods

DeleteResult

global DeleteResult()

ffrr.GroupingService.GroupingContext

global with sharing 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
GroupingCriteria List<ffrr.GroupingService.GroupingCriteria> The list of GroupingService.GroupingCriteria used to create grouping records.
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.
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.
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.
VersionId Id The ID of an existing StagingVersion__c to create primary groupings for.

Methods

GroupingContext

global GroupingContext()

ffrr.GroupingService.GroupingCriteria

global with sharing 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)

ffrr.GroupingService.GroupingOptions

global with sharing class GroupingOptions

Enables you to set options relating to grouping operations.

Properties

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

Methods

GroupingOptions

global GroupingOptions()

ffrr.GroupingService.GroupingResult

global with sharing 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.GroupingSummary

global with sharing class GroupingSummary

Contains the information of a Grouping Summary record.

Properties

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

Methods

GroupingSummary

global GroupingSummary()

© Copyright 2009–2023 Certinia Inc. All rights reserved. Various trademarks held by their respective owners.