Revenue Management API Developer Reference

ffrr.RevenueContractService

global with sharing class RevenueContractService

Methods

create

global static List<ffrr.RevenueContractService.ManageRevenueContractResult> create(List<ffrr.RevenueContractService.ManageRevenueContractContext> contexts)

Creates or updates revenue contracts with the source records provided.
If you do not provide a revenue contract, it is first created. After that, the method does the following:

  1. Creates performance obligations for the contract and performance obligation lines from the source records provided.
  2. Populates the fields on the performance obligation lines related to the revenue contract, based on their field mapping definition.
  3. Allocates revenue for all the performance obligations in the revenue contract.
  4. Generates revenue schedules for eligible performance obligations in the revenue contract. For more information, see "About Revenue Schedules" in the Revenue Management Help.
If steps 1 or 2 fail, the entire process is rolled back. Steps 3 and 4 are optional. If either of these fail, the previous steps are not rolled back. If step 3 fails, step 4 is not performed. The ffrr__RevenueRecognitionSettings__c.ffrr__DisableSchedulesCreationFromContracts__c custom setting controls whether to stop Revenue Schedules from being generated automatically as part of the asynchronous process. It defaults to false.

Depending on the contexts that you provide, the process runs synchronously or asynchronously. See the description below.
If the process runs asynchronously, you might receive an email notification once it finishes. This is determined by the value of ffrr__BatchSetting__c.ffrr__ManageRevenueContractSendEmail__c custom setting field.

Input Parameters

Name Type Description
contexts List<ffrr.RevenueContractService.ManageRevenueContractContext> List of contexts for creating or updating revenue contracts. Each context represents a single revenue contract to be created or updated. If you provide more than one context, the process runs asynchronously. If you provide a single context, the process might execute synchronously, depending on the number of source records.

Return Value

List of ManagementRevenueContractResult with a single instance.

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.

// In this example the Revenue Contract Service is used to synchronously create a new revenue contract.
// Performance obligations corresponding to the provided source records are created in the new revenue contract.
// Fields on the performance obligation lines related to revenue contract are populated.
// Revenue is allocated for all the performance obligations in the contract.
// Finally, revenue schedules are generated for the performance obligations.

ffrr.RevenueContractService.ManageRevenueContractContext context = new ffrr.RevenueContractService.ManageRevenueContractContext();

// Set the IDs of the source records that will be used to create performance obligations.
// The source records must not be linked to performance obligation lines in another revenue contract.
// The number of source records determines whether the process runs synchronously or asynchronously.
// In this example, we assume that you have provided five source records and that you haven't changed the default limit.
context.SourceRecordIds = selectedSourceRecords;

// You can optionally specify additional fields for the new revenue contract.
context.Contract = new ffrr.RevenueContractService.RevenueContract();
context.Contract.StartDate = Date.today();
context.Contract.EndDate = Date.today().addMonths(6);

// Add the context to a list of contexts.
List<ffrr.RevenueContractService.ManageRevenueContractContext> contexts = new List<ffrr.RevenueContractService.ManageRevenueContractContext>{context};

// Call the create method with the list of contexts.
List<ffrr.RevenueContractService.ManageRevenueContractResult> results = ffrr.RevenueContractService.create(contexts);

// The list of results contains a single instance of ManageRevenueContractResult.
// In this example, the Contract property from the result is populated with a representation of the new revenue contract.

// The Status property of the result contains the Allocation Status of the revenue contract.
// If an error occurs during the process, the Status property is set to "Error". In that case, use the Errors property to view the error.

// If an error occurs while generating revenue schedules, the error messages is also added to the Errors property.
// However, the Status properly still contains the Allocation Status of the revenue contract.

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.

// In this example the Revenue Contract Service is used to synchronously update an existing revenue contract
// using the specified source records to create performance obligations and performance obligation lines.
// Fields on the new performance obligation lines related to revenue contract are populated.
// Revenue is automatically reallocated for all the performance obligations in the revenue contract.
// Finally, revenue schedules are generated for the performance obligations. This includes both existing and new performance obligations.

ffrr.RevenueContractService.ManageRevenueContractContext context = new ffrr.RevenueContractService.ManageRevenueContractContext();

// Set the IDs of the source records that will be used to create performance obligations.
// The source records must not be linked to performance obligation lines in another revenue contract.
// Source records with performance obligations that are already linked to the specified revenue contract are ignored.
// The number of source records determines whether the process runs synchronously or asynchronously.
// In this example, we assume that you have provided five source records and that you haven't changed the default limit.
context.SourceRecordIds = selectedSourceRecords;

// Specify the ID of the revenue contract that will be updated with new performance obligations.
// We assume that you have already retrieved the ID of the revenue contract.
context.Contract = new RevenueContractService.RevenueContract();
context.Contract.Id = existingRevenueContractId;

// Add the context to a list of contexts.
List<ffrr.RevenueContractService.ManageRevenueContractContext> contexts = new List<ffrr.RevenueContractService.ManageRevenueContractContext>{context};

// Call the create method with the list of contexts.
List<ffrr.RevenueContractService.ManageRevenueContractResult> results = ffrr.RevenueContractService.create(contexts);

// The list of results contains a single instance of ManageRevenueContractResult.
// In this example, the Contract property from the result contains the newly created performance obligations.
// Existing performance obligations are excluded from the result.

// The Status property of the result contains the Allocation Status of the revenue contract.
// If an error occurs during the process, the Status property is set to "Error".
// In that case, use the Errors property to view the error.

// If an error occurs while generating revenue schedules, the error messages is also added to the Errors property.
// However, the Status properly still contains the Allocation Status of the revenue contract.

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.

// In this example the Revenue Contract Service is used to create two new revenue contracts asynchronously.
// After the performance obligations are created for each contract, fields on the performance obligation lines are populated
// and revenue is allocated for the all the performance obligations.
// Finally, revenue schedules are generated for the performance obligations of both contracts.
ffrr.RevenueContractService.ManageRevenueContractContext contextUSD = new ffrr.RevenueContractService.ManageRevenueContractContext();
contextUSD.SourceRecordIds = usdSourceRecordIds;

ffrr.RevenueContractService.ManageRevenueContractContext contextEUR = new ffrr.RevenueContractService.ManageRevenueContractContext();
contextEUR.SourceRecordIds = eurSourceRecordIds;

// Add the two contexts to a list of contexts.
List<ffrr.RevenueContractService.ManageRevenueContractContext> contexts = new List<ffrr.RevenueContractService.ManageRevenueContractContext>{contextUSD, contextEUR};

// Call the create method with the list of contexts.
// When the list contains multiple contexts, the process always runs asynchronously, regardless of the number of source records.
List<ffrr.RevenueContractService.ManageRevenueContractResult> results = ffrr.RevenueContractService.create(contexts);

// The list of results contains a single instance of ManageRevenueContractResult.
// Only the ProcessRunId property is populated. The remaining properties are set to null.

// You can retrieve the process run record to view additional information.
fferpcore__ProcessRun__c processRun = [SELECT Id FROM fferpcore__ProcessRun__c WHERE Id = :results[0].ProcessRunId LIMIT 1];
// The process run record contains the number of records pending to be processed,
// the number of successfully processed records, the number of errors, and the start and finish time.

// If the value of the ffrr__BatchSetting__c.ffrr__ManageRevenueContractSendEmail__c custom setting field is set to true,
// you will receive an email notification once the process finishes. This is set to true by default.
// The email contains a summary of the process run and a direct link to the process run record.

// If the value of the ffrr__RevenueRecognitionSettings__c.ffrr__DisableSchedulesCreationFromContracts__c custom setting field is set to true (default is false),
// the Revenue Schedule creation process will be skipped as part of the Revenue Contract creation.

populate

global static ffrr.RevenueContractService.PopulateResult populate(List<Id> contractIds)

Populates the fields on the Performance Obligation Line Items related to the specified Revenue Contracts based on their Field Mapping Definition. Field values on a Performance Obligation will also be updated from the Controlling Performance Obligation Line Item.

Input Parameters

Name Type Description
contractIds List<Id> The IDs of the Revenue Contract records that are related to the Performance Obligation Line Items to be populated.

Return Value

A RevenueContractService.PopulateResult that contains the Ids of the updated Performance Obligation Line Items and the updated Performance obligations.

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.

// In this example the Revenue Contract Service is used to update existing
// Performance Obligation Line Item Records based on their Filed Mapping Definitions.

// Retrieve the Ids of the Revenue Contracts that will be updated.
List<ffrr__RevenueContract__c> contracts = [SELECT Id FROM ffrr__RevenueContract__c WHERE ffrr__AccountName__c = 'FF'];
List<Id> contractIds = new List<Id>();

for( ffrr__RevenueContract__c contract : contracts )
{
    contractIds.add(contract.Id);
}

// Get the result that contains the Ids of the Performance Obligation Line Items
// and Performance Obligations that have been updated successfully.
ffrr.RevenueContractService.PopulateResult result = ffrr.RevenueContractService.populate(contractIds);

populateFromControllingPoli

global static List<Id> populateFromControllingPoli(List<id> performanceObligationIds)

Populates the Performance Obligation with the values from the controlling Performance Obligation Line Item. If the controlling Performance Obligation Line Item is not set, the first one based on the Name order will be used.

Input Parameters

Name Type Description
performanceObligationIds List<id> The IDs of the Performance Obligations to be populated.

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.

// In this example the Revenue Contract Service is used to populate existing
// Performance Obligation records with the values from their controlling
// Performance Obligation Line Item.

// Get the Ids of all the Performance Obligations under a specific contract.
Id contractId = [Select Id from ffrr__RevenueContract__c WHERE ffrr__Description__c = 'FF Contract' LIMIT 1].Id;
List<ffrr__PerformanceObligation__c> performanceObligations = [Select Id from ffrr__PerformanceObligation__c WHERE ffrr__RevenueContract__c = :contractId ];

List<Id> performanceObligationIds = new List<Id>();
for( ffrr__PerformanceObligation__c performanceObligation : performanceObligations )
{
    performanceObligationIds.add( performanceObligation.Id );
}

// Populate the Performance Obligations based on their controlling 
// Performance Obligation Line Item.
List<Id> updatedPerformanceObligations = ffrr.RevenueContractService.populateFromControllingPoli( performanceObligationIds );

populateFromControllingPoliFromContract

global static List<Id> populateFromControllingPoliFromContract(List<Id> contractIds)

Populates the Performance Obligations for the specified Revenue Contracts with the values from the controlling Performance Obligation Line Items. If the controlling Performance Obligation Line Item is not set, the first one based on the Name order will be used.

Input Parameters

Name Type Description
contractIds List<Id> The IDs of the Performance Obligations to be populated.

populateFromSourceRecords

global static ffrr.RevenueContractService.PopulateResult populateFromSourceRecords(ffrr.RevenueContractService.PopulateContext context)

Will update the Performance Obligation Line Items that can be found linking to the given source records, and in turn the Performance Obligation from the controlling Performance Obligation Line Item.
NB This uses a noticeable amount of SOQL queries, and as such should not be used where a trigger may be handling more than 1000 records. CPU time, which must be 'shared' with the calling process, may reduce that further in practice.
This currently requires both sharing and CRUD access to the Performance Obligation Line Items and Performance Obligation as well as the ability to read Settings and FieldMappings.

Input Parameters

Name Type Description
context ffrr.RevenueContractService.PopulateContext A RevenueContractService.PopulateContext object containing the source IDs to repopulate from.

Return Value

A RevenueContractService.PopulateResult that contains the Ids of the updated Performance Obligation Line Items and any updated Performance obligations.

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.

// In this example the Revenue Contract Service is used to update
// any existing Performance Obligation Line Items based on the source records
// which in this case are assumed to be the Opportunities (from an Opportunity trigger).


trigger UpdatePOLI on Opportunity (after update)
{
    ffrr.RevenueContractService.PopulateContext context = new ffrr.RevenueContractService.PopulateContext();

    for(SObject obj: Trigger.New)
    {
        context.SourceRecordIDs.add(obj.ID);
    }

    ffrr.RevenueContractService.populateFromSourceRecords( context );
}

populateFromSourceRecordsAsync

global static ID populateFromSourceRecordsAsync(ffrr.RevenueContractService.PopulateContext context)

This will start a queuable job to update Performance Obligation Line Items based on the source records indicated. The work done will be the same as populateFromSourceRecords, except that it happens via a queuable. The aysnc nature does mean that triggers that call this will not see any errors that occur during the populate.

Input Parameters

Name Type Description
context ffrr.RevenueContractService.PopulateContext A RevenueContractService.PopulateContext object containing the source IDs to repopulate from.

Return Value

The id of the queued job.

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.

// In this example the Revenue Contract Service is used to update
// any existing Performance Obligation Line Items based on the source records
// which in this case are assumed to be the Opportunities (from an Opportunity trigger).
// Calling the Async version will set off a queuable job to do the work, so the
// trigger is not affected by the update, but neither can it react to any failures to
// update the Performance Obligation Line Items.


trigger UpdatePOLI on Opportunity (after update)
{
    ffrr.RevenueContractService.PopulateContext context = new ffrr.RevenueContractService.PopulateContext();

    for(SObject obj: Trigger.New)
    {
        context.SourceRecordIDs.add(obj.ID);
    }

    ffrr.RevenueContractService.populateFromSourceRecordsAsync( context );
}

populatePerformanceObligationLineItems

global static ffrr.RevenueContractService.PopulateResult populatePerformanceObligationLineItems(List<Id> performanceObligationLineItemIds)

Populates the fields of the specified Performance Obligation Line Items based on their Field Mapping Definition. If one of the specified Performance Obligation Line Items is the controlling one, then the parent Performance Obligation is updated too.

Input Parameters

Name Type Description
performanceObligationLineItemIds List<Id> The IDs of the Performance Obligation Line Items to be populated.

Return Value

A RevenueContractService.PopulateResult that contains the Ids of the updated Performance Obligation Line Items and any updated Performance obligations.

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.

// In this example the Revenue Contract Service is used to update existing
// Performance Obligation Line Item Records based on their Filed Mapping Definitions.

// Retrieve the Ids of the Performance Obligation Line Items that will be updated.
List<ffrr__PerformanceObligationLineItem__c> lineItems = [SELECT Id FROM ffrr__PerformanceObligationLineItem__c WHERE ffrr__AccountName__c = 'FF'];
List<Id> lineItemIds = new List<Id>();

for( ffrr__PerformanceObligationLineItem__c lineItem : lineItems )
{
    lineItemIds.add(lineItem.Id);
}

// Get the result that contains the Ids of the Performance Obligation Line Items
// and Performance Obligations that have been updated successfully.
ffrr.RevenueContractService.PopulateResult result = ffrr.RevenueContractService.populatePerformanceObligationLineItems(lineItemIds);

populateRelatedPerformanceObligationLineItems

global static ffrr.RevenueContractService.PopulateResult populateRelatedPerformanceObligationLineItems(List<Id> performanceObligationIds)

Populates the fields on the Performance Obligation Line Items related to the specified Performance Obligations based on their Field Mapping Definition. Field values on a Performance Obligation will also be updated from the Controlling Performance Obligation Line Item.

Input Parameters

Name Type Description
performanceObligationIds List<Id> The IDs of the Performance Obligation records that are related to the Performance Obligation Line Items to be populated.

Return Value

A RevenueContractService.PopulateResult that contains the Ids of the updated Performance Obligation Line Items and the updated Performance obligations.

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.

// In this example the Revenue Contract Service is used to update the related
// Performance Obligation Line Item Records, of the provided Performance Obligations, 
// based on their Filed Mapping Definitions.

// Retrieve the Ids of the Performance Obligations.
List<ffrr__PerformanceObligation__c> obligations = [SELECT Id FROM ffrr__PerformanceObligation__c WHERE ffrr__AccountName__c = 'FF'];
List<Id> obligationIds = new List<Id>();

for( ffrr__PerformanceObligation__c obligation : obligations )
{
    obligationIds.add(obligation.Id);
}

// Get the result that contains the Ids of the Performance Obligation Line Items
// and Performance Obligations that have been updated successfully.
ffrr.RevenueContractService.PopulateResult result = ffrr.RevenueContractService.populateRelatedPerformanceObligationLineItems(obligationIds);

reallocate

global static void reallocate(List<Id> contractIds)

Calculates the Allocated Revenue for the Performance Obligation records related to the Revenue Contracts provided.

Input Parameters

Name Type Description
contractIds List<Id> The list of Revenue Contract IDs.

reallocatePerformanceObligations

global static void reallocatePerformanceObligations(List<Id> performanceObligationIds)

Calculates the Allocated Revenue for the supplied Performance Obligation records.

Input Parameters

Name Type Description
performanceObligationIds List<Id> The list of Performance Obligation IDs.

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 a subset of all the Performance Obligations to Allocate from a Revenue Contract
// e.g In a Batch execute method.
List<ffrr__PerformanceObligation__c> obligations = [SELECT Id FROM ffrr__PerformanceObligation__c WHERE ffrr__RevenueContract__c = :contractId LIMIT 200];

List<Id> obligationIds = new List<Id>();
for( ffrr__PerformanceObligation__c obligation : obligations )
{
    obligationIds.add(obligation.Id);
}

ffrr.RevenueContractService.reallocatePerformanceObligations(obligationIds);

retrieve

global static List<ffrr.RevenueContractService.RevenueContract> retrieve(List<Id> contractIds)

Retrieves a list of RevenueContract records based on their IDs.

Input Parameters

Name Type Description
contractIds List<Id> A list of the IDs of RevenueContracts to retrieve.

Return Value

A list of RevenueContract 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.

// In this example the Revenue Contract Service is used to retrieve existing
// Revenue Contracts and their related Performance Obligations.

// Create The Contracts and Performance Obligations to be returned.
// Create a Revenue Contract.
ffrr__RevenueContract__c contract = new ffrr__RevenueContract__c();
contract.ffrr__Description__c = 'Description';
insert contract;

// Create Performance Obligations.
ffrr__PerformanceObligation__c po1 = new ffrr__PerformanceObligation__c();
po1.ffrr__RevenueContract__c = contract.id;
po1.ffrr__Description__c = 'PO 1';

ffrr__PerformanceObligation__c po2 = new ffrr__PerformanceObligation__c();
po2.ffrr__RevenueContract__c = contract.id;
po2.ffrr__Description__c = 'PO 2';

insert new List<ffrr__PerformanceObligation__c> {po1, po2};

// Call the Service passing the Contract Id as a list.
List<ffrr.RevenueContractService.RevenueContract> result = ffrr.RevenueContractService.retrieve(new List<Id>{contract.Id});

// Get the Revenue Contract.
ffrr.RevenueContractService.RevenueContract returnedContract = result[0];

// Get the Performance Obligations for this Revenue Contract. Size should be 2.
List<ffrr.RevenueContractService.PerformanceObligation> performanceObligations = returnedContract.PerformanceObligations;

retrieve

global static List<ffrr.RevenueContractService.RevenueContract> retrieve(List<Id> contractIds, ffrr.RevenueContractService.RetrieveOptions options)

Retrieves a list of RevenueContract records based on their IDs.

Input Parameters

Name Type Description
contractIds List<Id> A list of the IDs of RevenueContracts to retrieve.
options ffrr.RevenueContractService.RetrieveOptions A RetrieveOptions object which specifies additional retrieve options

Return Value

A list of RevenueContract objects with list of Performance Obligations populated.

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.

// In this example the Revenue Contract Service is used to retrieve existing
// Revenue Contracts without their related Performance Obligations.

// Create The Contracts and Performance Obligations to be returned.
// Create a Revenue Contract.
ffrr__RevenueContract__c contract = new ffrr__RevenueContract__c();
contract.ffrr__Description__c = 'Description';
insert contract;

// Create Performance Obligations.
ffrr__PerformanceObligation__c po1 = new ffrr__PerformanceObligation__c();
po1.ffrr__RevenueContract__c = contract.id;
po1.ffrr__Description__c = 'PO 1';

ffrr__PerformanceObligation__c po2 = new ffrr__PerformanceObligation__c();
po2.ffrr__RevenueContract__c = contract.id;
po2.ffrr__Description__c = 'PO 2';

insert new List<ffrr__PerformanceObligation__c> {po1, po2};

// Create a new instance of RetrieveOptions.
ffrr.RevenueContractService.RetrieveOptions options = new ffrr.RevenueContractService.RetrieveOptions();

// Do not query for Performance Obligations.
options.IncludePerformanceObligations = false;

// Call the Service passing the Contract Id as a list.
List<ffrr.RevenueContractService.RevenueContract> result = ffrr.RevenueContractService.retrieve(new List<Id>{contract.Id}, options);

// Get the Revenue Contract.
ffrr.RevenueContractService.RevenueContract returnedContract = result[0];

// Get the Performance Obligations for this Revenue Contract. Size should be 2.
List<ffrr.RevenueContractService.PerformanceObligation> performanceObligations = returnedContract.PerformanceObligations;

retrievePerformanceObligations

global static Map<Id, List<ffrr.RevenueContractService.PerformanceObligation>> retrievePerformanceObligations(List<Id> contractIds)

Retrieves the Performance Obligation records related to the Revenue Contracts provided.

Input Parameters

Name Type Description
contractIds List<Id> The list of Revenue Contract IDs.

Return Value

Map of ffrr.RevenueContractService.PerformanceObligation by the ffrr__RevenueContract__c ID.

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 Revenue Contract.
ffrr__RevenueContract__c contract = new ffrr__RevenueContract__c();
contract.ffrr__Description__c = 'Description';
insert contract;

// Create Performance Obligations.
ffrr__PerformanceObligation__c po1 = new ffrr__PerformanceObligation__c();
po1.ffrr__RevenueContract__c = contract.id;
po1.ffrr__Description__c = 'PO 1';

ffrr__PerformanceObligation__c po2 = new ffrr__PerformanceObligation__c();
po2.ffrr__RevenueContract__c = contract.id;
po2.ffrr__Description__c = 'PO 2';

insert new List<ffrr__PerformanceObligation__c> {po1, po2};

// Call the Service.
Map<Id, List<ffrr.RevenueContractService.PerformanceObligation>> result = ffrr.RevenueContractService.retrievePerformanceObligations(new List<Id>{contract.Id});

savePerformanceObligations

global static ffrr.RevenueContractService.POSaveResult savePerformanceObligations(ffrr.RevenueContractService.POSaveContext saveContext)

Creates or updates Performance Obligations using the information provided.

Input Parameters

Name Type Description
saveContext ffrr.RevenueContractService.POSaveContext The save context containing the list of Performance Obligation records to be upserted, and records to be deleted.

Return Value

A POSaveResult containing the list of new and updated Performance Obligations and a POLISaveResult containing the list of new and updated Performance Obligations Line Items.

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.

// In this example the Revenue Contract Service is used to create and update Performance Obligations, and to create and update Performance Obligation Line Items.

/**
 * This section contains data setup.
 */

// Create the Revenue Contract.
ffrr__RevenueContract__c contract = new ffrr__RevenueContract__c();
insert contract;

// Create a Performance Obligation for the newly created Revenue Contract.
ffrr__PerformanceObligation__c performanceObligation = new ffrr__PerformanceObligation__c(
    ffrr__RevenueContract__c = contract.Id,
    ffrr__SSPOverride__c = 100
);
insert performanceObligation;

// Create a Performance Obligation Line Item for the newly created Performance Obligation.
ffrr__PerformanceObligationLineItem__c performanceObligationLineItem = new ffrr__PerformanceObligationLineItem__c(
    ffrr__PerformanceObligation__c = performanceObligation.Id,
    ffrr__AccountName__c = 'POLI Account Name'
);
insert performanceObligationLineItem;

// Set the new Line Item to be the Controlling POLI on the Performance Obligation.
performanceObligation.ffrr__ControllingPOLI__c = performanceObligationLineItem.Id;
update performanceObligation;

/**
 * End of data setup.
 */

/**
 * This section shows how to retrieve the records for manipulation, modify them, create new records, and save the changes.
 */

// Retrieve the Performance Obligations. These will also retrieve the Performance Obligation Line Items as a list property on the Performance Obligation.
List<Id> contractIds = new List<Id>{contract.Id};
Map<Id, List<ffrr.RevenueContractService.PerformanceObligation>> performanceObligationsByContractId = ffrr.RevenueContractService.retrievePerformanceObligations(contractIds);

// Update the SSP Override to 200.
List<ffrr.RevenueContractService.PerformanceObligation> performanceObligations = performanceObligationsByContractId.get(contract.Id);
ffrr.RevenueContractService.PerformanceObligation existingObligation = performanceObligations[0];
existingObligation.SSPOverride = 200;

// Create a new Performance Obligation Line Item and set the Account Name.
ffrr.RevenueContractService.PerformanceObligationLineItem newLineItemForExistingPO = new ffrr.RevenueContractService.PerformanceObligationLineItem();
newLineItemForExistingPO.AccountName = 'Example Account';

// Set the Controlling POLI on the new Line Item. This will cause the Controlling POLI to be updated to this Line Item.
// Setting 'IsControllingPOLI' on two or more Line Items belonging to the same Performance Obligation will result in an ffrr.Exceptions.AppException being thrown.
// Leaving 'IsControllingPOLI' set to NULL on all POLIs passed in will not change the Controlling POLI.
newLineItemForExistingPO.IsControllingPOLI = TRUE;
existingObligation.PerformanceObligationLineItems[0].IsControllingPOLI = FALSE;

// Add the new Line Item to the existing Performance Obligation.
existingObligation.PerformanceObligationLineItems.add(newLineItemForExistingPO);

// Create a new Performance Obligation.
ffrr.RevenueContractService.PerformanceObligation newObligation = new ffrr.RevenueContractService.PerformanceObligation();
newObligation.ContractId = contract.Id;
newObligation.SSPOverride = 300;

// Create a new Performance Obligation Line Item and set the Account Name.
ffrr.RevenueContractService.PerformanceObligationLineItem newLineItemForNewPO = new ffrr.RevenueContractService.PerformanceObligationLineItem();
newLineItemForNewPO.AccountName = 'New Example Account';

// Set the Controlling POLI on the new Line Item. This will cause the Controlling POLI to be updated to this Line Item.
// Setting 'IsControllingPOLI' on two or more Line Items belonging to the same Performance Obligation will result in an ffrr.Exceptions.AppException being thrown.
// Leaving 'IsControllingPOLI' set to NULL on all POLIs passed in will not change the Controlling POLI.
newLineItemForNewPO.IsControllingPOLI = TRUE;

// Create a new List of Line Items on the Performance Obligation containing the new Line Item.
newObligation.PerformanceObligationLineItems = new List<ffrr.RevenueContractService.PerformanceObligationLineItem>{newLineItemForNewPO};

// Add the new Performance Obligation to a list of Performance Obligations for saving.
List<ffrr.RevenueContractService.PerformanceObligation> newAndUpdatedPerformanceObligations = new List<ffrr.RevenueContractService.PerformanceObligation>{
    newObligation,
    existingObligation
};

ffrr.RevenueContractService.POSaveContext saveContext = new ffrr.RevenueContractService.POSaveContext();
saveContext.PerformanceObligations = newAndUpdatedPerformanceObligations;

// Save the new and updated Performance Obligations.
ffrr.RevenueContractService.POSaveResult result = ffrr.RevenueContractService.savePerformanceObligations(saveContext);

// Query the new Performance Obligations for use later on.
List<ffrr__PerformanceObligation__c> newPerformanceObligations = [SELECT Id, ffrr__SSPOverride__c FROM ffrr__PerformanceObligation__c WHERE ID IN :result.NewRecordIds];

// Query the updated Performance Obligations for use later on.
List<ffrr__PerformanceObligation__c> updatedPerformanceObligations = [SELECT Id, ffrr__SSPOverride__c FROM ffrr__PerformanceObligation__c WHERE ID IN :result.UpdatedRecordIds];

// Query all the new and updated Performance Obligations for use later on.
List<ffrr__PerformanceObligation__c> allPerformanceObligations = [SELECT Id, ffrr__SSPOverride__c FROM ffrr__PerformanceObligation__c WHERE ID IN :result.AllRecordIds];

searchRecords

global static Map<Schema.SObjectType, List<ffrr.ViewService.Reference>> searchRecords(String searchTerm)

Searches for Records that are related to ffrr_Settings__c, where ffrr__UseInRevenueContract__c is TRUE, that start with the search term in their Name Field. Maximum of 100 records for each SObject Type will be returned by default. Wildcards are supported.

Input Parameters

Name Type Description
searchTerm String The text to search for.

Return Value

A List of the records found keyed by their SObject Type.

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.

// In this example the Revenue Contract Service is used to search for source records that are related
// to ffrr_Settings__c, where ffrr__UseInRevenueContract__c is TRUE.

// Specify the term that matches the names of the source records.
// This will return any source record that starts with "Project" or "project".
String searchTerm = 'Project';

// Get the references of the source records, keyed by their type, matching the search term from the result.
Map<Schema.SObjectType, List<ffrr.ViewService.Reference>> result = ffrr.RevenueContractService.searchRecords( searchTerm );

searchRecords

global static Map<Schema.SObjectType, List<ffrr.ViewService.Reference>> searchRecords(String searchTerm, ffrr.RevenueContractService.RecordSearchOptions options)

Searches for Records that are related to ffrr_Settings__c, where ffrr__UseInRevenueContract__c is TRUE, that start with the search term in their Name Field. Wildcards are supported.

Input Parameters

Name Type Description
searchTerm String The text to search for.
options ffrr.RevenueContractService.RecordSearchOptions Enables you to set options related to searching.

Return Value

A List of the records found keyed by their SObject Type.

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.

// In this example the Revenue Contract Service is used to search for source records that are related
// to ffrr_Settings__c, where ffrr__UseInRevenueContract__c is TRUE.
// Additionally, a limit is used to reduce the number of results.

// Specify the term that matches the names of the source records.
// This will return any source record that starts with "Project" or "project".
String searchTerm = 'Project';

// Specify the maximum number of rows to be returned from the search operation.
ffrr.RevenueContractService.RecordSearchOptions options = new ffrr.RevenueContractService.RecordSearchOptions();
options.NumberOfRows = 10;

// Get the references of the first 10 source records, keyed by their type, matching the search term from the result.
Map<Schema.SObjectType, List<ffrr.ViewService.Reference>> result = ffrr.RevenueContractService.searchRecords( searchTerm );

searchRecords

global static Set<ffrr.RevenueContractService.SourceReference> searchRecords(String searchTerm, String objectName, List<String> filterPath, String currCode, ffrr.RevenueContractService.RecordSearchOptions options)

Searches for Records that are related to ffrr_Settings__c, where ffrr__UseInRevenueContract__c is TRUE and which are not associated with an existing Performance Obligation.

Input Parameters

Name Type Description
searchTerm String The text to search for (wildcards of '*' and '?' are supported).
objectName String The API name of the type of source object to search for (or '*' for all types).
filterPath List<String> The path (via lookups) to the field to search against (with the 'searchTerm') - this only applies with an 'objectname' to specify the starting point (otherwise the objects name field will be used).
currCode String The currency of the records we are searching for.
options ffrr.RevenueContractService.RecordSearchOptions Enables you to set options related to searching (e.g. 'NumberOfRows' to limit the number of rows returned).

Return Value

Information about the records found.

searchTemplates

global static List<ffrr.ViewService.Reference> searchTemplates(String searchTerm)

Searches for ffrr__Template__c records by name, whose related setting has an ffrr__object__c of ffrr__PerformanceObligation__c and ffrr__UseInRevenueContract__c is false. Returns 100 results by default.

Input Parameters

Name Type Description
searchTerm String The text to search for.

Return Value

A List of ViewService.Reference containing the Id and the name of matching results.

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.

// In this example the Revenue Service is used to search for templates, whose related Setting has an 
// ffrr__object__c of ffrr__PerformanceObligation__c and ffrr__UseInRevenueContract__c is false.

// Specify the term that matches the names of the templates.
// This will return any template that contains "Percent Complete"
String searchTerm = 'Percent Complete';

// Get the references of the templates matching the search term from the result.
List<ffrr.ViewService.Reference> result = ffrr.RevenueContractService.searchTemplates( searchTerm );

searchTemplates

global static List<ffrr.ViewService.Reference> searchTemplates(String searchTerm, ffrr.RevenueContractService.RecordSearchOptions options)

Searches for ffrr__Template__c records by name, whose related setting has an ffrr__object__c of ffrr__PerformanceObligation__c and ffrr__UseInRevenueContract__c is false.

Input Parameters

Name Type Description
searchTerm String The text to search for.
options ffrr.RevenueContractService.RecordSearchOptions Enables you to set options related to searching for templates.

Return Value

A List of ViewService.Reference containing the Id and the name of matching results.

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.

// In this example the Revenue Service is used to search for templates, whose related Setting has an 
// ffrr__object__c of ffrr__PerformanceObligation__c and ffrr__UseInRevenueContract__c is false.
// Additionally, a limit is used to reduce the number of results.

// Specify the term that matches the names of the templates.
// This will return any template that contains "Deliverable"
String searchTerm = 'Deliverable';

// Specify the maximum number of rows to be returned from the search operation.
ffrr.RevenueContractService.RecordSearchOptions options = new ffrr.RevenueContractService.RecordSearchOptions();
options.NumberOfRows = 10;

// Get the references of the first 10 templates matching the search term from the result.
List<ffrr.ViewService.Reference> result = ffrr.RevenueContractService.searchTemplates( searchTerm );

getSourceObjectInfo

global static Map<String, String> getSourceObjectInfo()

Searches for all the settings where ffrr__UseInRevenueContract__c is TRUE and which have a template.

Return Value

A map keyed by all the source objects in the selected settings with the object label as the map value.

transferPreviouslyRecognized

global static List<ffrr.RevenueContractService.TransferResult> transferPreviouslyRecognized(ffrr.RevenueContractService.TransferContext context)

Creates In Progress Revenue Recognition Transactions with Transaction Lines for Performance Obligation Line records provided that are related to source records with committed Transactions. Transaction Lines are only created for active Performance Obligations with valid templates.

Input Parameters

Name Type Description
context ffrr.RevenueContractService.TransferContext Specifies wich records will be included in the process as well as the information that will be put on the created Transactions.

Return Value

The List of the created Revenue Recognition Transaction IDs.

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.

// In this example the Revenue Contract Service is used to create Revenue Recognition Transactions
// for specific Performance Obligation records that are related to source records with committed Transactions.

// Select the Performance Obligation Line Items related to the source records. Any "Committed" Revenue, no later than the cutoff date,
// will be taken into account from this proccess.

// The following selects the Performance Obligation Line Items whose related contract's start date is after the 2017-01-01.
Date startOf2017 = Date.newInstance(2017, 01, 01);
List<ffrr__PerformanceObligationLineItem__c> lineItems = [SELECT Id FROM ffrr__PerformanceObligationLineItem__c WHERE ffrr__PerformanceObligation__r.ffrr__RevenueContract__r.ffrr__StartDate__c >= :startOf2017];
List<Id> lineItemIds = new List<Id>();
for( ffrr__PerformanceObligationLineItem__c lineItem : lineItems )
{
    lineItemIds.add(lineItem.Id);
}

// Create the Transfer Context.
ffrr.RevenueContractService.TransferContext context = new ffrr.RevenueContractService.TransferContext();

context.RecognitionDate = Date.newInstance(2017, 1, 1);
context.CutoffDate = Date.newInstance(2016, 12, 31);
context.Description = 'Previously recognized before 2017';
context.LegislationType = 'ASC 605';
context.Period = [SELECT Id FROM ffrr__RecognitionPeriod__c WHERE Name = '2017/001' LIMIT 1].Id;

// Set the Performance Obligation Line Item Ids to the context.
context.PerformanceObligationLineItems = lineItemIds;

// Retrieve the result containing the created Transactions.
List<ffrr.RevenueContractService.TransferResult> result = ffrr.RevenueContractService.transferPreviouslyRecognized(context);

transferPreviouslyRecognizedAsync

global static Id transferPreviouslyRecognizedAsync(ffrr.RevenueContractService.TransferContext context)

Creates In Progress Revenue Recognition Transactions with Transaction Lines for all Performance Obligation records that are related to source records with committed Transactions. Transaction Lines are only created for active Performance Obligations with valid templates.

Input Parameters

Name Type Description
context ffrr.RevenueContractService.TransferContext Specifies wich records will be included in the process as well as the information that will be put on the created Transactions.

Return Value

The ID of the AsyncApexJob.

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.

// In this example the Revenue Contract Service is used to create Revenue Recognition Transactions asynchronously
// for all the Performance Obligation records that are related to source records with committed Transactions.

ffrr.RevenueContractService.TransferContext context = new ffrr.RevenueContractService.TransferContext();
context.RecognitionDate = Date.newInstance(2016, 1, 1);
context.CutoffDate = Date.newInstance(2015, 12, 31);
context.Description = 'Previously recognized before 2016';
context.LegislationType = 'ASC 605';
context.Period = [SELECT Id FROM ffrr__RecognitionPeriod__c WHERE Name = '2017/001' LIMIT 1].Id;

// Retrieve the Id of the Batch Job that's been started.
Id resultingBatchId = ffrr.RevenueContractService.transferPreviouslyRecognizedAsync(context);

ffrr.RevenueContractService.DeleteContext

global abstract with sharing class DeleteContext

base class that details revenue contracts and related records to be deleted

Properties

Name Type Description
ContractsToDelete List<Id> the ids of the revenue contract records to be deleted
PerformanceObligationsToDelete List<Id> the ids of the performance obligation records to be deleted
POLIsToDelete List<Id> the ids of the performance obligation line item records to be deleted

Methods

DeleteContext

global DeleteContext()

ffrr.RevenueContractService.Filter

global with sharing class Filter

the filter class used to specify field/value pairs when filtering on revenue contracts during the transfer previously recognized process.

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 text field Filter
ffrr.RevenueContractService.Filter textFilter = new ffrr.RevenueContractService.Filter();

// Set the field to filter on to be the Description__c field. This could be any text or lookup field.
textFilter.Field = ffrr__RevenueContract__c.ffrr__Description__c;

// Set the value to filter on.
textFilter.Value = 'Ready for Transfer';

// You can also create filters for Lookups and Booleans
ffrr.RevenueContractService.Filter booleanFilter = new ffrr.RevenueContractService.Filter();

// Set the field to filter on to be the Description__c field. This could be any text or lookup field.
booleanFilter.Field = ffrr__RevenueContract__c.ffrr__Active__c;

// Set the value to filter on.
booleanFilter.Value = 'true';

ffrr.RevenueContractService.Filter lookupFilter = new ffrr.RevenueContractService.Filter();

// Set the field to filter on to be the Description__c field. This could be any text or lookup field.
lookupFilter.Field = ffrr__RevenueContract__c.ffrr__Account__c;

// Set the value to filter on.
lookupFilter.Value = [SELECT Id FROM Account LIMIT 1].Id;

Properties

Name Type Description
Field Schema.SObjectField the field on the revenue contract on which to filter.
Value Object the value for the filter.

Methods

Filter

global Filter()

ffrr.RevenueContractService.PathItem

global with sharing class PathItem

contains information about a step in the metadata chain.

Properties

Name Type Description
ItemLabel String the label of the sobject at this point in the path.
RecordName String the type of the sobject at this point in the path.

ffrr.RevenueContractService.PerformanceObligation

global with sharing class PerformanceObligation

represents a performance obligation record

Properties

Name Type Description
Id Id the id of the performance obligation
Name String the name of the performance obligation
AccountName String information about the performance obligation. often this will be the account name, but it can be any information.
Active Boolean specifies whether the performance obligation is active
AllocatedRevenue Decimal the allocated revenue of the performance obligation
AllocatedRevenueOverride Decimal the allocated revenue override of the performance obligation
AmortizedToDate Decimal the amount amortized to date for this performance obligation.
BalanceSheet String the balance sheet name for the performance obligation
Complete Boolean specifies whether the performance obligation is complete
ContractId Id the revenue contract of the performance obligation
Cost Decimal cost for this performance obligation.
CostBalanceSheet String the name of the balance sheet gla (cost) for this performance obligation.
CostCenter String the cost center name for the performance obligation
CostCostCenter String the cost center (cost) for this performance obligation.
CostIncomeStatement String the name of the income statement gla (cost) for this performance obligation.
CurrencyIsoCode String the currency code of the performance obligation
Description String the description of the performance obligation
IncomeStatement String the income statement name for the performance obligation
PercentComplete Decimal the percentage the performance obligation is complete
PerformanceObligationLineItems List<ffrr.RevenueContractService.PerformanceObligationLineItem>
ReadyForRevRec Boolean specifies whether the performance obligation is ready for revenue recognition
RecognizedToDate Decimal the recognized to date of the performance obligation
Revenue Decimal the revenue of the performance obligation
RevRecComplete Boolean specifies whether the performance obligation is revenue recognition complete
SSP Decimal the ssp of the performance obligation
TotalSSP Decimal sum of the ssps for all performance obligation line items in the Performance Obligation.
SSPOverride Decimal the ssp override for the performance obligation
StartDate Date the start date of the performance obligation
EndDate Date the end date of the performance obligation
Template ffrr.ViewService.Reference the template of the performance obligation

Methods

PerformanceObligation

global PerformanceObligation()

ffrr.RevenueContractService.PerformanceObligationLineItem

global with sharing class PerformanceObligationLineItem

represents a performance obligation line item record.

Properties

Name Type Description
Id Id the id of the performance obligation line item.
Name String the name of the performance obligation line item.
AccountName String the reference for the performance obligation line item.
Active Boolean indicates whether the performance obligation line item is active.
BalanceSheetAccount String the balance sheet gla of the performance obligation line item.
Completed Boolean indicates whether the performance obligation line item is complete.
Cost Decimal cost for this performance obligation line item.
CostBalanceSheetAccount String balance sheet gla (cost)
CostCenterAccount String the cost center account of the performance obligation line item.
CostCostCenterAccount String cost center (cost)
CostIncomeStatementAccount String income statement gla (cost)
CurrencyIsoCode String the currency of the performance obligation line item.
Description String the description of the performance obligation line item.
FieldMapping ffrr.ViewService.Reference the field mapping definition of the performance obligation line item. This determines which fields get populated from Source Records when "Update from Source" occurs.
IncomeStatementAccount String the income statement gla of the performance obligation line item.
IsControllingCostPOLI Boolean indicates whether the performance obligation line item is the cost controlling Performance Obligation Line Item. The Performance Obligation will take Cost specific vaues from the Cost Controlling Performance Obligation Line Item when "Update from Source" occurs. The cost controlling POLI will only be used to populate the more general fields on the Performance Obligation in the scenario whereby a controlling revenue POLI has not be specified at all.
IsControllingPOLI Boolean indicates whether the performance obligation line item is the revenue controlling Performance Obligation Line Item. The Performance Obligation will take Revenue specific values from the Revenue Controlling Performance Obligation Line Item when "Update from Source" occurs. The revenue controlling POLI will get priority when populating the more general fields on the Performance Obligation.
PercentageComplete Decimal the percentage that this performance obligation line item is complete, using the scale of 100 to denote 100%.
PerformanceObligationId Id the id of the performance obligation this performance obligation line item belongs to.
Revenue Decimal the revenue for the performance obligation line item.
SSP Decimal the ssp of the performance obligation line item.
SourceRecord ffrr.ViewService.Reference the source record linked to this performance obligation line item.
SourceRecordSetting ffrr.ViewService.Reference the setting used by the source record related to this performance obligation line item.
StartDate Date the start date of the performance obligation line item.
EndDate Date the end date of the performance obligation line item.
ValueType String the value-type from the source records settings.

Methods

PerformanceObligationLineItem

global PerformanceObligationLineItem()

ffrr.RevenueContractService.PopulateContext

global with sharing class PopulateContext

object that wraps the ids that are needed for the populatefromsourcerecords methods.

Properties

Name Type Description
SourceRecordIDs List<Id> the ids of the source records that are to be used to find performance obligation line items that need updating from those source records.

Methods

PopulateContext

global PopulateContext()

ffrr.RevenueContractService.PopulateResult

global with sharing class PopulateResult

contains information resulting from the populate operation.

Properties

Name Type Description
UpdatedPolis List<Id> the ids of the updated performance obligation line items.
UpdatedPos List<Id> the ids of the updated performance obligations.

ffrr.RevenueContractService.POLISaveResult

global with sharing class POLISaveResult extends SaveResult

This class extends ffrr.RevenueContractService.SaveResult

ffrr.RevenueContractService.POSaveContext

global with sharing class POSaveContext extends DeleteContext

specifies information needed to save performance obligations

This class extends ffrr.RevenueContractService.DeleteContext

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.

// This example creates a new POSaveContext ready to be passed to the ffrr.RevenueContractService.savePerformanceObligations() method.

// Create a new POSaveContext.
ffrr.RevenueContractService.POSaveContext saveContext = new ffrr.RevenueContractService.POSaveContext();

// Pass in your list of Performance Obligations to update.
saveContext.PerformanceObligations = new List<ffrr.RevenueContractService.PerformanceObligation>();

/*
 * Pass in record IDs to delete.
 * The order in which records are deleted is as follows:
 * 1: ffrr__PerformanceObligationLineItem__c
 * 2: ffrr__PerformanceObligation__c
 * 3: ffrr__RevenueContract__c
 *
 * Deleting a Revenue Contract will delete all related Performance Obligations and Line Items,
 * and deleting a Performance Obligation will delete all related Line Items.
 */
// Pass in any Contract IDs you want to delete.
saveContext.ContractsToDelete = new List<Id>();

// Pass in any Performance Obligation IDs you want to delete.
saveContext.PerformanceObligationsToDelete = new List<Id>();

// Pass in any Performance Obligation Line Item IDs you want to delete.
saveContext.POLIsToDelete = new List<Id>();

Properties

Name Type Description
PerformanceObligations List<ffrr.RevenueContractService.PerformanceObligation> the list of performance obligation records to be upserted.

Methods

POSaveContext

global POSaveContext()

ffrr.RevenueContractService.POSaveResult

global with sharing class POSaveResult extends SaveResult

contains the results of the performance obligation save operation

This class extends ffrr.RevenueContractService.SaveResult

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.

// This list should be populated with RevenueContractService.PerformanceObligations,
// and each of those should contain a list of RevenueContractService.PerformanceObligationLineItems.
List<ffrr.RevenueContractService.PerformanceObligation> newAndUpdatedPerformanceObligations = new List<ffrr.RevenueContractService.PerformanceObligation>();

ffrr.RevenueContractService.POSaveContext saveContext = new ffrr.RevenueContractService.POSaveContext();
saveContext.PerformanceObligations = newAndUpdatedPerformanceObligations;

// Save the new and updated Performance Obligations.
ffrr.RevenueContractService.POSaveResult result = ffrr.RevenueContractService.savePerformanceObligations(saveContext);

// Query the new Performance Obligations.
List<ffrr__PerformanceObligation__c> newPerformanceObligations = [SELECT Id, ffrr__SSPOverride__c FROM ffrr__PerformanceObligation__c WHERE ID IN :result.NewRecordIds];

// Query the updated Performance Obligations.
List<ffrr__PerformanceObligation__c> updatedPerformanceObligations = [SELECT Id, ffrr__SSPOverride__c FROM ffrr__PerformanceObligation__c WHERE ID IN :result.UpdatedRecordIds];

// Query all the new and updated Performance Obligations.
List<ffrr__PerformanceObligation__c> allPerformanceObligations = [SELECT Id, ffrr__SSPOverride__c FROM ffrr__PerformanceObligation__c WHERE ID IN :result.AllRecordIds];

// Get the Line Item results.
ffrr.RevenueContractService.POLISaveResult lineItemResult = result.POLISaveResult;

// Query the new Performance Obligation Line Items.
List<ffrr__PerformanceObligationLineItem__c> newPerformanceObligationLineItems = [SELECT Id, ffrr__AccountName__c FROM ffrr__PerformanceObligationLineItem__c WHERE ID IN :lineItemResult.NewRecordIds];

// Query the updated Performance Obligation Line Items.
List<ffrr__PerformanceObligationLineItem__c> updatedPerformanceObligationLineItems = [SELECT Id, ffrr__AccountName__c FROM ffrr__PerformanceObligationLineItem__c WHERE ID IN :lineItemResult.UpdatedRecordIds];

// Query all the new and updated Performance Obligation Line Items.
List<ffrr__PerformanceObligationLineItem__c> allPerformanceObligationLineItems = [SELECT Id, ffrr__AccountName__c FROM ffrr__PerformanceObligationLineItem__c WHERE ID IN :lineItemResult.AllRecordIds];

Properties

Name Type Description
POLISaveResult ffrr.RevenueContractService.POLISaveResult

ffrr.RevenueContractService.RecordSearchOptions

global with sharing class RecordSearchOptions

enables you to set options related to searching for 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.

// Use the Record Search Options to specify the maximum number of results
// to be returned from the Search Templates operation.
ffrr.RevenueContractService.RecordSearchOptions options = new ffrr.RevenueContractService.RecordSearchOptions();
options.NumberOfRows = 10;

Properties

Name Type Description
NumberOfRows Integer The maximum number of results to be returned

Methods

RecordSearchOptions

global RecordSearchOptions()

ffrr.RevenueContractService.RetrieveOptions

global with sharing class RetrieveOptions

contains additional options related to retrieving revenuecontract instances

Properties

Name Type Description
IncludePerformanceObligations Boolean specifies whether to retrieve performanceobligation instances along with their parent revenue contract. defaults to true.

Methods

RetrieveOptions

global RetrieveOptions()

ffrr.RevenueContractService.RevenueContract

global with sharing class RevenueContract

represents a revenue contract record

Properties

Name Type Description
Id Id the id of the revenue contract
Name String the name of the revenue contract
AccountName String the reference for the revenue contract
AccountId Id id of the account record that the revenue contract relates to.
Active Boolean specifies whether the revenue contract is active
AllocationRatio Decimal the ratio used to allocate revenue to linked performance obligations
AllocationStatus String shows if the revenue for this contract has been fully allocated, or needs reallocating
CurrencyIsoCode String the currency code of the revenue contract
Description String the description of the revenue contract
PerformanceObligations List<ffrr.RevenueContractService.PerformanceObligation> all performance obligations related to this contract
PerformanceObligationsCount Decimal the number of performance obligations on this contract
Revenue Decimal the value that will be allocated to the performance obligations. uses total revenue, or revenue override if populated
RevenueAllocated Boolean indicates if the revenue for this contract has been allocated successfully
RevenueRecognitionComplete Boolean indicates whether this revenue contract is complete
SourceRecordId Id ID of the source record that the revenue contract relates to.
This is mapped to the lookup field defined in the ffrr__RevenueRecognitionSettings__c.ffrr__RevenueContractSourceRecordLookup__c custom setting field.
StartDate Date the start date of the revenue contract
EndDate Date the end date of this revenue contract
TotalAllocatedRevenue Decimal total allocated revenue for this revenue contract
TotalAllocatedRevenueOverride Decimal sum of allocated revenue override values from all linked performance obligations
TotalAmortizedToDate Decimal total amortized to date for this revenue contract
TotalCost Decimal total cost for this revenue contract
TotalRecognizedToDate Decimal total recognized to date for this revenue contract
TotalSSP Decimal sum of standalone selling prices from all linked performance obligations

Methods

RevenueContract

global RevenueContract()

ffrr.RevenueContractService.ManageRevenueContractContext

global with sharing class ManageRevenueContractContext

Context used when creating or updating a revenue contract. Contains information about the revenue contact and the related source 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 an instance of ManageRevenueContractContext to provide the source records when
// creating or updating a revenue contract.

// Create a new instance of ManageRevenueContractContext
ffrr.RevenueContractService.ManageRevenueContractContext context = new ffrr.RevenueContractService.ManageRevenueContractContext();

// Retrieve the IDs of source records used to create performance obligations
// The list can contain IDs from different objects
// We recommend using one of the searchRecords methods to retrieve only source records that are not already linked to a performance obligation.
// In this example, we retrieve all PSA projects related to the engagement with the name of ENG0000000.
ffrr.RevenueContractService.RecordSearchOptions options = new ffrr.RevenueContractService.RecordSearchOptions();
options.NumberOfRows = 5;

List<String> lookupPath = new List<String> { 'pse__Engagement__c','Name' };

Set<ffrr.RevenueContractService.SourceReference> sourceRecordsReference =
  ffrr.RevenueContractService.searchRecords('ENG0000000','pse__Proj__c', lookupPath, 'USD', options);

List<Id> sourceRecordsIds = new List<Id>();
for(ffrr.RevenueContractService.SourceReference source : sourceRecords) {
  sourceRecordsIds.add(source.Id);
}

context.SourceRecordIds = sourceRecordsIds;

// Use the Contract property to specify which revenue contract is being updated.
context.Contract = new ffrr.RevenueContractService.RevenueContract();
context.Contract.Id = [SELECT Id FROM ffrr__RevenueContract__c WHERE Name = 'ContractName' LIMIT 1].Id;
// If you are creating a new revenue contract, you can leave the Contract property as null,
// or, you can specify the following optional fields:
//    - AccountId
//    - Description
//    - CurrencyIsoCode
//    - SourceRecordId
//    - StartDate
//    - EndDate
context.Contract.AccountId = [SELECT Id FROM Account WHERE Name = 'AccountName' LIMIT 1].Id;
context.Contract.Description = 'Contract for engagement: ENG0000000';
context.Contract.CurrencyIsoCode = 'USD';
context.Contract.SourceRecordId = 'a1B0t000003hS8oEAE';
context.Contract.StartDate = Date.today();
context.Contract.EndDate = Date.today().addMonths(6);

Properties

Name Type Description
Contract ffrr.RevenueContractService.RevenueContract Represents the revenue contract record to be created or updated.
Optional when creating a revenue contract, required when updating a revenue contract.
If you are creating a new revenue contract, you can provide the following properties:
- AccountId
- Description
- CurrencyIsoCode
- SourceRecordId
- StartDate
- EndDate
If you are updating a revenue contract, you must provide the Id property.
Any other properties that you might provide are ignored.
SourceRecordIds List<Id> List of source records used to create performance obligations and performance obligation lines for the revenue contract.
If you call the ffrr__RevenueContractService.create method with a single context, the number of source records determines whether the process runs synchronously or asynchronously. This is determined based on the value of the ffrr__BatchSetting__c.ffrr__ManageRevenueContractSynchronousLimit__c custom setting field.
Note that the source records must not be linked to performance obligation lines in another revenue contract. If a source record is linked to a performance obligation line in the specified revenue contract, it is ignored.
fieldMappingDefinitionId Id Id of Field Mapping Definition that will be used to do any additional field mapping between fields on the contract source record and the Revenue Contract to be created. If an update call and a previous field mapping has been used, the update will overwrite the previously mapped values and will apply any additional field mappings.
If this value is null then no additional mapping will take place
The Field Mapping Definition must have source object type equal to that of the contract source record, and it must have target object type equal to the RevenueContract__c object type

ffrr.RevenueContractService.ManageRevenueContractResult

global with sharing class ManageRevenueContractResult

Contains information resulting from the create or update revenue contract process.
Different properties are populated depending on whether the process runs synchronously or asynchronously.

Properties

Name Type Description
Errors List<String> List of errors that occurred during the synchronous process. Null if no errors occurred or when the process runs asynchronously.
ProcessRunId Id ID of the related fferpcore__ProcessRun__c record when the process runs asynchronously.
You can query the process run to view the status of the execution, the related child process runs, and the related logs. For more information, see "fferpcore.ffasync_ProcessService" in the Foundations Apex API Developer Reference documentation.
Null when the process is executed synchronously.
Contract ffrr.RevenueContractService.RevenueContract Represents the revenue contract that was created or updated synchronously.
The PerformanceObligations property only contains the performance obligations that were created, existing obligations are excluded. The PerformanceObligationsCount property contains the total number of performance obligations in the revenue contract, including existing obligations.
Null when the process runs asynchronously.
Status String Final status of the synchronous process. Set to one of the following:
- "Error"
- Value of the ffrr__AllocationStatus__c field of the revenue contract
Null when the process runs asynchronously.

ffrr.RevenueContractService.SaveResult

global abstract with sharing class SaveResult

contains the results of the save operation

Properties

Name Type Description
AllRecordIds List<Id> the ids of both the created and updated records.
NewRecordIds List<Id> the ids of created records.
UpdatedRecordIds List<Id> the ids of updated records.

Methods

SaveResult

global SaveResult()

ffrr.RevenueContractService.SourceReference

global with sharing class SourceReference

contains information about the records found from the search process.

Properties

Name Type Description
Id String the id of the source record this class contains information about.
AccountName String the account name of the source record.
Description String the description of the source record.
SelectPath List<ffrr.RevenueContractService.PathItem> the search path used to find this record.
SettingsPath List<ffrr.RevenueContractService.PathItem> the hierarchy of parent records leading to this source record.
ValueType String the value-type from the source records settings.

ffrr.RevenueContractService.TransferContext

global with sharing class TransferContext

@decription The context in which the Transfer Previously Recognized process will be executed.

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 Transfer context to specify how the Transfer Previously Recognized process
// will be executed.

// Select the period the Recognition Transaction will be created for. 
Date recognitionDate = Date.newInstance(2016, 1, 1);

List<ffrr__RecognitionPeriod__c> periods = [SELECT Id FROM ffrr__RecognitionPeriod__c WHERE ffrr__StartDate__c <= :recognitionDate AND ffrr__EndDate__c >= :recognitionDate];

// Select an "In Progress" Transaction to Update.
List<ffrr__RevenueRecognitionTransaction__c> transactions = [SELECT Id FROM ffrr__RevenueRecognitionTransaction__c WHERE ffrr__Status__c = 'In Progress' AND ffrr__Description__c = 'FinancialForce.com' LIMIT 1];
List<Id> transactionIds = new List<Id>();
for( ffrr__RevenueRecognitionTransaction__c trans : transactions )
{
    transactionIds.add(trans.Id);
}

// Select the Performance Obligation Line Items related to the source records. Any "Committed" Revenue to be used
// Recognition Transaction related to those source records will be taken into account from this proccess.
Date startOf2017 = Date.newInstance(2017, 01, 01);
List<ffrr__PerformanceObligationLineItem__c> lineItems = [SELECT Id FROM ffrr__PerformanceObligationLineItem__c WHERE ffrr__PerformanceObligation__r.ffrr__RevenueContract__r.ffrr__StartDate__c >= :startOf2017];
List<Id> lineItemIds = new List<Id>();
for( ffrr__PerformanceObligationLineItem__c lineItem : lineItems )
{
    lineItemIds.add(lineItem.Id);
}

// Create the Transfer Context.
ffrr.RevenueContractService.TransferContext context = new ffrr.RevenueContractService.TransferContext();

// Set the Performance Obligation Line Item Ids to the context.
context.PerformanceObligationLineItems = lineitemIds;

// Set the transction to be updated.
context.TransactionIds = transactionIds;

// Specify the Period that will be put on the Recognition Transactions
context.Period = periods[0].Id;

// Specify the Recognition Date and Description that will be on the Revenue Recognition Transactions
context.RecognitionDate = recognitionDate;
context.Description = 'Previously recognized before 2016';

// Specify the Cutoff Date that will be used to determine which Transactions will be used to transfer Previously Recognized.
context.CutoffDate = Date.newInstance(2015, 12, 31);

// Specify the legislation type for the Transactions that will be created.
context.LegislationType = 'ASC 605';

// Specify the filter to limit which Performance Obligation Line Items get selected.
// For this example we will filter where the Account.Name is 'FinancialForce'
ffrr.RevenueContractService.Filter filter = new ffrr.RevenueContractService.Filter();

// Set the field to filter on to be the Description__c field. This could be any text or lookup field.
filter.Field = ffrr__RevenueContract__c.ffrr__Account__c;

// Set the value to filter on.
filter.Value = [SELECT Id FROM Account WHERE Name = 'FinancialForce' LIMIT 1].Id;

context.RevenueContractFilters = new List<ffrr.RevenueContractService.Filter>{filter};

Properties

Name Type Description
CutoffDate Date specifies the committed revenue recognition transactions that will be used from the Transfer Process. Only committed Transactions where the Recognition Date is up to the cutoff date will be used.
Description String the description on the created transaction.
LegislationType String the legislation type on the created transaction.
PerformanceObligationLineItems List<Id> the performance obligation lines related to source records with committed Transactions that will be used by the process. (Optional)
Period String the recognition period the transactions will be created for.
RecognitionDate Date the recognition date the transactions will be created for.
TransactionIds List<Id> specifies transactions to be amended with transaction lines. (optional) New Transaction Lines created from the Performance Obligation Line Items specified will be amended to the given Transactions of the same currency. The Transactions specified in this list must be of different currencies.
RevenueContractFilters List<ffrr.RevenueContractService.Filter> specifies which revenue contracts are eligible for transferring previously recognized by providing key-value pairs of filters.

Methods

TransferContext

global TransferContext()

ffrr.RevenueContractService.TransferResult

global with sharing class TransferResult

Properties

Name Type Description
ActiveTransaction Id
CurrencyCode String
GroupName String
TransactionIds List<Id>
error Exception
© Copyright 2009–2022 FinancialForce.com, inc. All rights reserved. Various trademarks held by their respective owners.