Revenue Management API Developer Reference

ffrr.RecordMappingService

global with sharing class RecordMappingService

Maps values from source record to a target record. The class is with sharing to enforce the sharing rules.

Methods

transferValues

global static ffrr.RecordMappingService.TransferResult transferValues(List<ffrr.RecordMappingService.TransferContext> contexts)

Transfers field values from a source record to one or more target records.

Input Parameters

Name Type Description
contexts List<ffrr.RecordMappingService.TransferContext> Specifies the source and target records as well as the underlying fields to copy from and to.

Return Value

An instance of TransferResult containing the data resulting from the update operation.

Sample Code

//Note: This sample code is for demonstration purposes only. It is not intended for
//use in a production environment, is not guaranteed against defects or errors, and
//is in no way optimized or streamlined.

// In this example the record mapping service maps a value from
// one Product, and a Fixed Value, to multiple Orders. When mapping an ID to a String
// we use the Name field of the ID record to transfer.

String sourceValue = 'Source Record';
DateTime fixedValue = System.now();

// Create a product for the source record.
Product2 product = new Product2();
product.Name = sourceValue;
insert product;

// Create an order which is going to be the target record.
Order order = new Order();
order.Name = 'Target Record';
order.EffectiveDate = System.today();
order.Status = 'Draft';
order.AccountId = [SELECT Id from Account WHERE Name = 'United Sales'][0].Id;
insert order;

Id orderId = order.Id;

// Create a TransferContext for each source record to map from.
ffrr.RecordMappingService.TransferContext transferContext = new ffrr.RecordMappingService.TransferContext();

// // Set the SourceRecordId of the record to map values from.
transferContext.SourceRecordId = product.Id;

// Set the TargetRecordIds of the records to map values to.
transferContext.TargetRecordIds = new List<Id>{order.Id};

// Create a fieldMapping for each source field to map from.
ffrr.RecordMappingService.FieldMapping fieldMappingFromSource = new ffrr.RecordMappingService.FieldMapping();

// Set the source field to map values from.
fieldMappingFromSource.SourceField = Schema.Product2.Name;

// Specify if you want to use the Name field when mapping an ID field to a String field
fieldMappingFromSource.UseRecordName = true;

// Set the target field to map to.
fieldMappingFromSource.TargetFields = new List<Schema.SObjectField>{Schema.Order.Description};

// Create a fieldMapping for each fixed value to map.
ffrr.RecordMappingService.FieldMapping fieldMappingFixedValue = new ffrr.RecordMappingService.FieldMapping();

// Set the fixed value to use when mapping.
fieldMappingFixedValue.FixedValue = fixedValue;

// Set the target field to map to.
fieldMappingFixedValue.TargetFields = new List<Schema.SObjectField>{Schema.Order.ActivatedDate};

// Set the Field Mappings on the transfer context.
transferContext.FieldMappings = new List<ffrr.RecordMappingService.FieldMapping>{fieldMappingFromSource, fieldMappingFixedValue};

// Call the update method.
ffrr.RecordMappingService.TransferResult result = ffrr.RecordMappingService.transferValues(new List<ffrr.RecordMappingService.TransferContext>{transferContext});

// Make sure that the value is mapped correctly.
Order updatedRecord = [SELECT Description, ActivatedDate FROM Order WHERE Id = :order.Id];
System.assertEquals(sourceValue, updatedRecord.Description, 'The record should now have the mapped value.');
System.assertEquals(fixedValue, updatedRecord.ActivatedDate, 'The record should now have the mapped value.');

transferValues

global static ffrr.RecordMappingService.TransferResult transferValues(List<ffrr.RecordMappingService.TransferContext> contexts, Boolean withSecurity)

Transfers field values from a source record to one or more target records.

Input Parameters

Name Type Description
contexts List<ffrr.RecordMappingService.TransferContext> Specifies the source and target records as well as the underlying fields to copy from and to.
withSecurity Boolean If false the sharing model rules will not be applied throughout the execution.

Return Value

An instance of TransferResult containing the data resulting from the update operation.

Sample Code

//Note: This sample code is for demonstration purposes only. It is not intended for
//use in a production environment, is not guaranteed against defects or errors, and
//is in no way optimized or streamlined.

// In this example the record mapping service maps a value from
// one Product to multiple Orders, without taking into consideration the sharing rules.
//  When mapping an ID to a String we use the ID to transfer.

String sourceValue = 'Source Record';

// Create a product for the source record.
Product2 product = new Product2();
product.Name = sourceValue;
insert product;

// Create an order which is going to be the target record.
Order order = new Order();
order.Name = 'Target Record';
order.EffectiveDate = System.today();
order.Status = 'Draft';
order.AccountId = [SELECT Id from Account WHERE Name = 'United Sales'][0].Id;
insert order;

Id orderId = order.Id;

// Create a TransferContext for each source record to map from.
ffrr.RecordMappingService.TransferContext transferContext = new ffrr.RecordMappingService.TransferContext();

// // Set the SourceRecordId of the record to map values from.
transferContext.SourceRecordId = product.Id;

// Set the TargetRecordIds of the records to map values to.
transferContext.TargetRecordIds = new List<Id>{order.Id};

// Create a fieldMapping for each source field to map from.
ffrr.RecordMappingService.FieldMapping fieldMapping = new ffrr.RecordMappingService.FieldMapping();

// Set the source field to map values from.
fieldMapping.SourceField = Schema.Product2.Name;

// Set the target field to map to.
fieldMapping.TargetFields = new List<Schema.SObjectField>{Schema.Order.Description};

// Specify if you want to use the Name field when mapping an ID field to a String field
FieldMapping.UseRecordName = false;

// Set the Field Mapping to the transfer context.
transferContext.FieldMappings = new List<ffrr.RecordMappingService.FieldMapping>{fieldMapping};

// Call the update method by specifying FALSE to the "withSecurity" parameter.
ffrr.RecordMappingService.TransferResult result = ffrr.RecordMappingService.transferValues(new List<ffrr.RecordMappingService.TransferContext>{transferContext}, false);

// Make sure that the value is mapped correctly.
String updatedRecord = [SELECT Description FROM Order WHERE Id = :order.Id].Description;
System.assert(updatedRecord == sourceValue, 'The record should now have the mapped value.');

ffrr.RecordMappingService.FieldMapping

global with sharing class FieldMapping

Specifies the mapping between the source field where the values will be transferred from to the target fields where the values will be transferred to.

Properties

Name Type Description
FixedValue Object A fixed value to use for copying.
SourceField Schema.SObjectField The field that the values will be transferred from.
TargetFields List<Schema.SObjectField> The fields that the values will be transferred to.
UseRecordName Boolean Indicates when transferring values from ID to String whether the Name of the record should be tranferred.

Methods

FieldMapping

global FieldMapping()

A convertor that manipulates the value in the source field before setting it in the target fields.

ffrr.RecordMappingService.TransferContext

global with sharing class TransferContext

Contains information required to map a source record's field values to one or more target records.

Properties

Name Type Description
FieldMappings List<ffrr.RecordMappingService.FieldMapping> List of FieldMapping instances specifying which source fields will be copied to the corresponding target fields.
SourceRecordId Id ID of the record that the field values will be transferred from.
TargetRecordIds List<Id> List of records that the field values will be transferred to.

Methods

TransferContext

global TransferContext()

ffrr.RecordMappingService.TransferResult

global with sharing class TransferResult

Container for data resulting from an update operation.

Properties

Name Type Description
Ids List<Id> List of the record IDs that have been updated.

Methods

TransferResult

global TransferResult()

© Copyright 2009–2022 FinancialForce.com, inc. All rights reserved. Various trademarks held by their respective owners.