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

// Assuming there are three 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 template mapping records can also be created via the salesforce UI

// Assigns the Deliverable 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 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 template to any timecard records that do not match to any of the other 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 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–2020 FinancialForce.com, inc. All rights reserved. Various trademarks held by their respective owners.