pse.SObjectCloneMapperglobal virtual with sharing class SObjectCloneMapper The pse.SObjectCloneMapper class allows you to define the structure of SObjects that you want to clone. This object can be used by a cloning service to describe the data to be copied. Properties
MethodsSObjectCloneMapperglobal SObjectCloneMapper(Schema.SObjectType sObjectTypeToClone, Set<pse.SObjectCloneMapper.Field> sObjectFieldsToClone) A Default constructor with minimum required properties. Input Parameters
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. // Define the object fields which are required to be cloned. // Define the default value to be used for the field. When not defined, the value is copied from the template project. pse.SObjectCloneMapper.Field mapperField1 = new pse.SObjectCloneMapper.Field(Schema.pse__Proj__c.Name); mapperField1.defaultValue = 'MapperProjectName'; pse.SObjectCloneMapper.Field mapperField2 = new pse.SObjectCloneMapper.Field(Schema.pse__Proj__c.pse__Is_Active__c); mapperField2.DefaultValue = true; pse.SObjectCloneMapper.Field mapperField3 = new pse.SObjectCloneMapper.Field(Schema.pse__Proj__c.pse__Is_Billable__c); mapperField3.DefaultValue = true; // Group together the pse.SObjectCloneMapper.Field instantiated above for each object and prepare a set. Set<pse.SObjectCloneMapper.Field> setMapperFields = new Set<pse.SObjectCloneMapper.Field>{mapperField1, mapperField2, mapperField3}; // Instantiate the pse.SObjectCloneMapper using the prepared set of pse.SObjectCloneMapper.Field for each object. pse.SObjectCloneMapper mapp = new pse.SObjectCloneMapper(pse__Proj__c.SObjectType, setMapperFields); pse.SObjectCloneMapper.NullFieldValueglobal inherited sharing class NullFieldValue Used to represent an explicit null value. When the DefaultValue of a field is set to an instance of this class, the cloned records are created with a null in that field. The cloner should copy values for that field from the template when a default value is not provided. 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. /** * As an example, pse__Action_Date__c is a custom field and has been added to pse__Proj__c. This field has a default * value such that when a new project is created, the pse__Action_Date__c is set to a month in the future. The template * has a value in pse__Action_Date__c which should not be present in the cloned project. When a project is copied from * this template using pse.CreateProjectFromTemplateService, the business rules are that it should not have a date * in this field. If pse__Action_Date__c is given to pse.CreateProjectFromTemplateService (either as a mapper, or in a * FieldSet) then the tool will copy the value from the template. If the field is not provided, then the project is * created with a default value of next month. By using NullFieldValue, the cloned project can be created with null pse__Action_Date__c. */ // Define a Field for pse__Action_Date__c to force the value to be null in the cloned project and not copy the value from the template project. pse.SObjectCloneMapper.Field actionDateFieldMapper = new pse.SObjectCloneMapper.Field(Schema.pse__Proj__c.pse__Action_Date__c); actionDateFieldMapper.DefaultValue = new pse.SObjectCloneMapper.NullFieldValue(); // Instantiate the SObjectCloneMapper using the prepared set of pse.SObjectCloneMapper.Field for each object. pse.SObjectCloneMapper mapp = new pse.SObjectCloneMapper(pse__Proj__c.SObjectType, new Set<pse.SObjectCloneMapper.Field>{actionDateFieldMapper}); // Prepare the required fields for the ProjectRequest instance to be created. Id templateProjectId = Id.valueOf('a1Q000000000000'); // Our template project. Date startDateForProject = Date.Today(); pse.CreateProjectFromTemplateService.CreateProjectFromTemplateRequest request = new pse.CreateProjectFromTemplateService.CreateProjectFromTemplateRequest(templateProjectId, startDateForProject); request.mappers = new List<pse.SObjectCloneMapper> { mapp }; // Pass the request to the service which will create the project with no date in pse__Action_Date__c as intended. pse.CreateProjectFromTemplateService.createProjectsFromTemplate( new List<pse.CreateProjectFromTemplateService.CreateProjectFromTemplateRequest>{request}); pse.SObjectCloneMapper.Fieldglobal inherited sharing class Field Each Field provides information about a field on the sObject you want to clone. Add instances of this class to SObjectFieldsToClone on SObjectCloneMapper. Properties
MethodsFieldglobal Field(Schema.SObjectField field) A default constructor with minimum required properties. Input Parameters
|