Revenue Management API Developer Reference

ffrr.TemplateMappingService

global with sharing class TemplateMappingService

Provides a stateless method to populate templates on records from a trigger context.

Methods

populateTemplate

global static void populateTemplate(List<SObject> records)

Populates the templates associated to the source records as configured in the Recognition Template Mapping (ffrr__TemplateMapping__c) records. This can only be used from a trigger context and will only populate the template when the records are inserted

Input Parameters

Name Type Description
records List<SObject> The source records that the templates should be populated on

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 assumes the setup for recognition settings and recognition templates has been carried out for this example.
// In this example this is the TimeCard__c object.

// Assuming there are three recognition templates ('Deliverable','Equal Split', '% Complete')
List<ffrr__Template__c> templates = [SELECT ID FROM ffrr__Template__c WHERE ffrr__RevRecType__c IN ('Deliverable','Equal Split', '% Complete') AND ffrr__Settings__r.ffrr__Object__c = 'TimeCard__c' ORDER BY ffrr__RevRecType__c];

//These recognition template mapping records can also be created via the Salesforce UI.

// Assigns the Deliverable recognition template to any timecard records where the 'RecognitionMethod__c' field is equal to 'Deliverable'
ffrr__TemplateMapping__c deliverableTemplateMapping = new ffrr__TemplateMapping__c();
deliverableTemplateMapping.ffrr__ObjectName__c = 'TimeCard__c';
deliverableTemplateMapping.ffrr__Template__c = templates[0].Id;
deliverableTemplateMapping.ffrr__CriteriaField__c = 'RecognitionMethod__c';
deliverableTemplateMapping.ffrr__CriteriaField__c = 'Deliverable';

// Assigns the Equal Split recognition template to any timecard records where the 'RecognitionMethod__c' field is equal to 'Equal Split'
ffrr__TemplateMapping__c equalSplitTemplateMapping = new ffrr__TemplateMapping__c();
equalSplitTemplateMapping.ffrr__ObjectName__c = 'TimeCard__c';
equalSplitTemplateMapping.ffrr__Template__c = templates[1].Id;
equalSplitTemplateMapping.ffrr__CriteriaField__c = 'RecognitionMethod__c';
equalSplitTemplateMapping.ffrr__CriteriaField__c = 'Equal Split';

// Assigns the % Complete recognition template to any timecard records that do not match to any of the other recognition template mapping records
ffrr__TemplateMapping__c defaultTemplateMapping = new ffrr__TemplateMapping__c();
defaultTemplateMapping.ffrr__ObjectName__c = 'TimeCard__c';
defaultTemplateMapping.ffrr__Template__c = templates[2].Id;
defaultTemplateMapping.ffrr__CriteriaField__c = '';
defaultTemplateMapping.ffrr__CriteriaField__c = '';

// Create the below trigger replacing TimeCard__c with the object that recognition templates are to be populated for.
// Alternatively add the trigger body to an existing trigger for the given object.
trigger PopulateTemplate on TimeCard__c (before insert)
{
    ffrr.TemplateMappingService.populateTemplate(Trigger.new);
}
© Copyright 2009–2023 Certinia Inc. All rights reserved. Various trademarks held by their respective owners.