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 recognition schedules for eligible performance obligations in the revenue contract. For more information, see "About Recognition 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 Recognition 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, recognition 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 recognition 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, recognition 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 recognition 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, recognition 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 Recognition 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 Recognition 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 recognition templates, whose related Recognition 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 recognition template that contains "Percent Complete"
String searchTerm = 'Percent Complete';

// Get the references of the recognition 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 recognition templates, whose related Recognition 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 recognition templates.
// This will return any recognition 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 recognition 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 recognition 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 recognition settings with the object label as the map value.

transferPreviouslyRecognized

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

Creates In Progress 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 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 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 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 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 cost recognized 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 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 recognition 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 Cost Recognized To Date for this Revenue Contract
TotalCost Decimal Total cost for this Revenue Contract
TotalRecognizedToDate Decimal Total Revenue 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 recognition 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 = 'Certinia' 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 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 'Certinia'
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 = 'Certinia' LIMIT 1].Id;

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

Properties

Name Type Description
CutoffDate Date Specifies the committed 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–2024 Certinia Inc. All rights reserved. Various trademarks held by their respective owners.