pse.CreateProjectFromTemplateServiceglobal with sharing class CreateProjectFromTemplateService A service used to clone one or more projects from templates. You can use this service in conjunction with SObjectCloneMapper, as the mappers on a clone request, to add extra fields to objects or extra objects that are copied from the template. You must include the fields describing the relationship between extra objects and the template project. Methods
createProjectsFromTemplatesglobal static List<pse.CreateProjectFromTemplateService.CreateProjectResponse> createProjectsFromTemplates(List<pse.CreateProjectFromTemplateService.CreateProjectFromTemplateRequest> requests) This method creates new projects from a project template using details provided in the CreateProjectFromTemplateRequest list. The following configuration is used: Input Parameters
Return ValueThis service returns CreateProjectResponses in a list that parallels the input list. 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. // Prepare the required fields for the CreateProjectFromTemplateRequest instance to be created. Date startDateForProject = Date.Today();// Give a project start date to be used to populate the start date of project. Id templateProjectId = Id.valueOf('a1Q1a0000006VJ4');// Give a valid template project Id to clone the new project. // Instantiate the request to create project from template. pse.CreateProjectFromTemplateService.CreateProjectFromTemplateRequest PROJ_REQ1 = new pse.CreateProjectFromTemplateService.CreateProjectFromTemplateRequest(templateProjectId, startDateForProject); pse.CreateProjectFromTemplateService.CreateProjectFromTemplateRequest PROJ_REQ2 = new pse.CreateProjectFromTemplateService.CreateProjectFromTemplateRequest(templateProjectId, startDateForProject); // Call the service to create the projects using the request list and store a list of responses. List<pse.CreateProjectFromTemplateService.CreateProjectResponse> PROJ_RESPONSES = pse.CreateProjectFromTemplateService.createProjectsFromTemplates( new List<pse.CreateProjectFromTemplateService.CreateProjectFromTemplateRequest>{PROJ_REQ1, PROJ_REQ2}); // Loop for each response and detect whether requests were successfully processed. for(pse.CreateProjectFromTemplateService.CreateProjectResponse response : PROJ_RESPONSES) { if( response.isSuccess() ) // Get the new project Ids from the response when successfully processed in the request. { System.debug('Request for this response :' + response.request); System.debug('New project Id for the successful cloned project :' + response.NewProjectId); // All related information can be queried using this project Id. } else // Get the errors from the response for unsuccessful requests. { System.debug('Request for this response :' + response.Request); System.debug('Errors related to unsuccessful request :' + response.Errors); } } createProjectsFromTemplatesglobal static List<pse.CreateProjectFromTemplateService.CreateProjectResponse> createProjectsFromTemplates(List<pse.CreateProjectFromTemplateService.CreateProjectFromProjectRequest> requests) This method creates new projects from a project template using details provided in the CreateProjectFromTemplateRequest list. The following configuration is used: Input Parameters
Return ValueThis service returns CreateProjectResponses in a list that parallels the input list. createProjectsFromTemplatesglobal static List<pse.CreateProjectFromTemplateService.CreateProjectResponse> createProjectsFromTemplates(List<pse.CreateProjectFromTemplateService.CreateProjectFromTemplateAndAccountRequest> requests) This method creates new projects from a project template using details provided in the requests list. The project will be linked to the account ID passed in the CreateProjectFromTemplateAndAccountRequest. The following configuration is used: Input Parameters
Return ValueThis service returns CreateProjectResponses in a list that parallels the input list. 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. // Prepare the required fields for the AccountRequest instance to be created. Date startDateForProject = Date.Today();// Give a start date to populate the project. Id templateProjectId = Id.valueOf('a1Q000000000000');// Give a valid template project Id to clone the new project. Id accountId = Id.valueOf('001000000000000');// Give a valid account Id to link to the new project. // Instantiate the request for create project from template. pse.CreateProjectFromTemplateService.CreateProjectFromTemplateAndAccountRequest ACC_PROJ_REQ1 = new pse.CreateProjectFromTemplateService.CreateProjectFromTemplateAndAccountRequest(accountId, templateProjectId, startDateForProject); // Call the service to create the projects using the request list and store list of response List<pse.CreateProjectFromTemplateService.CreateProjectResponse> ACC_PROJ_RESPONSES = pse.CreateProjectFromTemplateService.createProjectsFromTemplates( new List<pse.CreateProjectFromTemplateService.CreateProjectFromTemplateAndAccountRequest>{ACC_PROJ_REQ1}); // Loop for each response to detect whether all requests were successfully processed. for(pse.CreateProjectFromTemplateService.CreateProjectResponse response : ACC_PROJ_RESPONSES) { if( response.isSuccess() ) // Get the new project Ids from the response when successfully processed in the request. { System.debug('Request for this response :' + response.Request); System.debug('New project Id for the successful cloned project :' + response.NewProjectId); // All related information can be queried using this project Id. } else // Get the errors from the response for an unsuccessful request. { System.debug('Request for this response :' + response.Request); System.debug('Errors related to unsuccessful request :' + response.Errors); } } createProjectsFromTemplatesglobal static List<pse.CreateProjectFromTemplateService.CreateProjectResponse> createProjectsFromTemplates(List<pse.CreateProjectFromTemplateService.CreateProjectFromTemplateAndOpportunityRequest> requests) This method creates new projects from a template project using details provided in the CreateProjectFromTemplateAndOpportunityRequest list. The project will be linked to the opportunity ID passed in the CreateProjectFromTemplateAndOpportunityRequest. The following configuration is used: Input Parameters
Return ValueThis service returns CreateProjectResponses in a list that parallels the input list. 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. // Prepare the required fields for the OpportunityRequest instance to be created. Date startDateForProject = Date.Today();// Provide a start date to populate the project. Id templateProjectId = Id.valueOf('a1Q1a0000006VJ4');// Provide a valid template project Id to clone the new project. Id opportunityId = Id.valueOf('00637000005rwZq');// Provide a valid opportunity Id to link to the new project. // Instantiate the request. pse.CreateProjectFromTemplateService.CreateProjectFromTemplateAndOpportunityRequest OPP_PROJ_REQ1 = new pse.CreateProjectFromTemplateService.CreateProjectFromTemplateAndOpportunityRequest(opportunityId, templateProjectId, startDateForProject); // Call the service to create the projects using the request list and store a list of responses. List<pse.CreateProjectFromTemplateService.CreateProjectResponse> OPP_PROJ_RESPONSES = pse.CreateProjectFromTemplateService.createProjectsFromTemplates( new List<pse.CreateProjectFromTemplateService.CreateProjectFromTemplateAndOpportunityRequest>{OPP_PROJ_REQ1}); // Loop for each response to detect whether all requests were successfully processed. for(pse.CreateProjectFromTemplateService.CreateProjectResponse response : OPP_PROJ_RESPONSES) { if( response.isSuccess() ) // Obtain the new project Ids from the response when successfully processed in the request. { System.debug('Request for this response :' + response.request); System.debug('New project Id for the successful cloned project :' + response.NewProjectId); // All related information can be queried using this project Id. } else // Obtain the errors from the response for an unsuccessful request. { System.debug('Request for this response :' + response.Request); System.debug('Errors related to unsuccessful request :' + response.Errors); } } pse.CreateProjectFromTemplateService.CreateProjectRequestglobal with sharing abstract class CreateProjectRequest The request structure for the CreateProjectFromTemplateService. Properties
pse.CreateProjectFromTemplateService.CreateProjectFromTemplateRequestglobal with sharing class CreateProjectFromTemplateRequest extends CreateProjectRequest The request structure for creating projects from templates only. To be used with createProjectsFromTemplates. This class extends pse.CreateProjectFromTemplateService.CreateProjectRequest MethodsCreateProjectFromTemplateRequestglobal CreateProjectFromTemplateRequest(Id templateProjectId, Date startDate) 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 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); // Prepare the required fields for the ProjectRequest instance to be created. Id templateProjectId = Id.valueOf('a1Q000000000000');// Give a valid template project Id used to clone the new project. Date startDateForProject = Date.Today();// Provide a project start date. pse.CreateProjectFromTemplateService.CreateProjectFromTemplateRequest PROJ_REQ1 = new pse.CreateProjectFromTemplateService.CreateProjectFromTemplateRequest(templateProjectId, startDateForProject); pse.CreateProjectFromTemplateService.CreateProjectFromTemplateRequest PROJ_REQ2 = new pse.CreateProjectFromTemplateService.CreateProjectFromTemplateRequest(templateProjectId, startDateForProject); PROJ_REQ1.IsActive = true; PROJ_REQ1.IsTemplate = false; PROJ_REQ1.ProjectName = 'ExampleProjectName'; PROJ_REQ1.ProjectOwnerId = Id.valueOf('0051a000000aeDc'); PROJ_REQ1.Mappers = new List<pse.SObjectCloneMapper> { mapp }; PROJ_REQ2.IsActive = true; PROJ_REQ2.IsTemplate = false; PROJ_REQ2.ProjectName = 'ExampleProjectNameSecond'; PROJ_REQ2.ProjectOwnerId = Id.valueOf('0051a000000aeDc'); PROJ_REQ2.Mappers = new List<pse.SObjectCloneMapper> { mapp }; pse.CreateProjectFromTemplateService.CreateProjectFromProjectRequestglobal with sharing class CreateProjectFromProjectRequest extends CreateProjectRequest The request structure for creating projects from any other project. To be used with createProjectsFromTemplates. This class extends pse.CreateProjectFromTemplateService.CreateProjectRequest MethodsCreateProjectFromProjectRequestglobal CreateProjectFromProjectRequest(Id templateProjectId, Date startDate) A default constructor with minimum required properties. Input Parameters
pse.CreateProjectFromTemplateService.CreateProjectFromTemplateAndAccountRequestglobal with sharing class CreateProjectFromTemplateAndAccountRequest extends CreateProjectRequest The request structure for creating projects from templates with certain data coming from an account. To be used with createProjectsFromTemplatesAndAccounts. This class extends pse.CreateProjectFromTemplateService.CreateProjectRequest Properties
MethodsCreateProjectFromTemplateAndAccountRequestglobal CreateProjectFromTemplateAndAccountRequest(Id accountId, Id templateProjectId, Date startDate) 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 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); // Prepare the required fields for the AccountRequest instance to be created. Account account = [Select Id from Account where Name = 'Customer1']; // Give the name of the account to associate with the new cloned project. pse__Proj__c proj = [Select Id from pse__Proj__c where pse__Project_ID__c = 'PR-000038']; // Give a valid template project name for the new cloned project. Id accountId = account.Id; Id templateProjectId = proj.Id; Date startDateForProject = Date.Today();// Give a project start date to populate the new cloned project start date. pse.CreateProjectFromTemplateService.CreateProjectFromTemplateAndAccountRequest ACC_PROJ_REQ1 = new pse.CreateProjectFromTemplateService.CreateProjectFromTemplateAndAccountRequest(accountId, templateProjectId, startDateForProject); ACC_PROJ_REQ1.IsActive = true; ACC_PROJ_REQ1.IsTemplate = false; ACC_PROJ_REQ1.ProjectName = 'ExampleProjectName'; ACC_PROJ_REQ1.ProjectOwnerId = Id.valueOf('0051a000000aeDc'); ACC_PROJ_REQ1.Mappers = new List<pse.SObjectCloneMapper> { mapp }; pse.CreateProjectFromTemplateService.CreateProjectFromTemplateAndOpportunityRequestglobal with sharing virtual class CreateProjectFromTemplateAndOpportunityRequest extends CreateProjectRequest The request structure for creating projects from templates with certain data coming from an opportunity. To be used with createProjectsFromTemplatesAndOpportunities. This class extends pse.CreateProjectFromTemplateService.CreateProjectRequest Properties
MethodsCreateProjectFromTemplateAndOpportunityRequestglobal CreateProjectFromTemplateAndOpportunityRequest(Id opportunityId, Id templateProjectId, Date startDate) 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 required object fields to be cloned. // Define the default value to be used for the field. When not defined, the value is copied from the template project. // When default values are not defined for CurrencyIsoCode, Region, Practice, Group and Account, values are copied from the associated opportunity. // When a default value is not provided for a Name, the value is generated based on the opportunity name and configuration. 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 SObjectCloneMapper using the prepared set of SObjectCloneMapper.Field for each object. pse.SObjectCloneMapper cloneMap = new pse.SObjectCloneMapper(pse__Proj__c.SObjectType, setMapperFields); // Prepare the required fields for the OpportunityRequest instance to be created. Opportunity useOpportunity = [Select Id from Opportunity where Name = 'Test_Clone_Opportunity']; // Provide the name of the opportunity to associate with the newly cloned project. pse__Proj__c proj = [Select Id from Proj__c where Project_ID__c = 'PR-000038']; // Provide a valid template project name for the newly cloned project. Id opportunityId = useOpportunity.Id; Id templateProjectId = proj.Id; Date startDateForProject = Date.Today();// Provide a project start date to populate the new cloned project. pse.CreateProjectFromTemplateService.CreateProjectFromTemplateAndOpportunityRequest OPP_PROJ_REQ1 = new pse.CreateProjectFromTemplateService.CreateProjectFromTemplateAndOpportunityRequest(opportunityId, templateProjectId, startDateForProject); OPP_PROJ_REQ1.IsActive = true; OPP_PROJ_REQ1.IsTemplate = false; OPP_PROJ_REQ1.ProjectName = 'ExampleProjectName'; OPP_PROJ_REQ1.ProjectOwnerId = Id.valueOf('0051a000000aeDc'); OPP_PROJ_REQ1.Mappers = new List<pse.SObjectCloneMapper> { cloneMap }; pse.CreateProjectFromTemplateService.CreateProjectFromProjectAndOpportunityRequestglobal with sharing class CreateProjectFromProjectAndOpportunityRequest extends CreateProjectFromTemplateAndOpportunityRequest The request structure for creating projects based on other projects and including data from an opportunity. To be used with createProjectsFromTemplates. This class extends pse.CreateProjectFromTemplateService.CreateProjectFromTemplateAndOpportunityRequest MethodsCreateProjectFromProjectAndOpportunityRequestglobal CreateProjectFromProjectAndOpportunityRequest(Id opportunityId, Id templateProjectId, Date startDate) pse.CreateProjectFromTemplateService.CreateProjectResponseglobal inherited sharing class CreateProjectResponse The response structure returned for each request passed to createProjectsFromTemplates. Properties
MethodsisSuccessglobal Boolean isSuccess() Indicates whether the project was successfully created. Even if isSuccess() is false, it is possible that the project was still created. That can happen, for example, when the there was a problem creating a budget to link to the new project. pse.CreateProjectFromTemplateService.CreateProjectErrorglobal with sharing class CreateProjectError Stores error messages that occur when executing methods from CreateProjectFromTemplateService. Properties
|