ffrr.RecordMappingServiceglobal with sharing class RecordMappingService Maps values from source record to a target record. The class is with sharing to enforce the sharing rules. Methods
transferValuesglobal 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
Return ValueAn 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.'); transferValuesglobal 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
Return ValueAn 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.FieldMappingglobal 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
MethodsFieldMappingglobal FieldMapping() A convertor that manipulates the value in the source field before setting it in the target fields. ffrr.RecordMappingService.TransferContextglobal with sharing class TransferContext Contains information required to map a source record's field values to one or more target records. Properties
MethodsTransferContextglobal TransferContext() ffrr.RecordMappingService.TransferResultglobal with sharing class TransferResult Container for data resulting from an update operation. Properties
MethodsTransferResultglobal TransferResult() |