csc.CreateSuccessPlanFromTemplateServiceglobal with sharing class CreateSuccessPlanFromTemplateService Used to create success plans from templates. Exposes the API for mass creation of success plans from templates. Note: Ensure that all lookups and related records have the same account when creating success plans. MethodscreateSuccessPlansFromTemplatesglobal static List<csc.CreateSuccessPlanFromTemplateResponse> createSuccessPlansFromTemplates(List<csc.CreateSuccessPlanFromTemplateRequest> requests) Used to create multiple success plans from templates using a list of requests. Input Parameters
Return ValueList<CreateSuccessPlanFromTemplateResponse> 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.
// Make a list of requests to call the API with.
final List<csc.CreateSuccessPlanFromTemplateRequest> requests = new List<csc.CreateSuccessPlanFromTemplateRequest>();
// Provide the IDs of the templates that you want to create success plans from.
final Id templateId1 = 'a1MDR000001fnI52AI';
// Make a map of fields to populate on the new success plan and values to populate them with.
final Map<SObjectField, Object> fieldsToPopulate1 = new Map<SObjectField, Object>{
csc__Success_Plan__c.Name => '1st API-generated success plan',
csc__Success_Plan__c.csc__Effective_Date__c => Date.newInstance(2023, 5, 8)
};
// Set options to be used during processing. Options is an enum datatype that includes the value COPY_CS_SKILLS_FROM_PLAYBOOK and IS_SYNCHRONOUS_PROCESS.
Set<csc.CreateSuccessPlanFromTemplateRequest.Options> options1 = new Set<csc.CreateSuccessPlanFromTemplateRequest.Options>();
// Add COPY_CS_SKILLS_FROM_PLAYBOOK value into the option. It is an enum datatype, if present in the parameter, will copy skills from the playbook.
// If you do not want to copy skills, you can either use the constructor without any options or pass the option without the value COPY_CS_SKILLS_FROM_PLAYBOOK.
options1.add(csc.CreateSuccessPlanFromTemplateRequest.Options.COPY_CS_SKILLS_FROM_PLAYBOOK);
// Add IS_SYNCHRONOUS_PROCESS value into the option. It is an Enum datatype, if present in the parameter, it will run the process synchronously.
// If you want to run the process asynchronously, you can either use the constructor without any options or pass the option without the value IS_SYNCHRONOUS_PROCESS.
options1.add(csc.CreateSuccessPlanFromTemplateRequest.Options.IS_SYNCHRONOUS_PROCESS);
// Instantiate a request by providing a template ID and a map of fields to populate.
final csc.CreateSuccessPlanFromTemplateRequest request1 = new csc.CreateSuccessPlanFromTemplateRequest(
templateId1,
fieldsToPopulate1,
options1
);
requests.add(request1);
// Prepare parameters for the additional CreateSuccessPlanFromTemplateRequest instance to be created.
final Id templateId2 = 'a1MDR000001fnRL2AY';
final Map<SObjectField, Object> fieldsToPopulate2 = new Map<SObjectField, Object>{
csc__Success_Plan__c.Name => '2nd API-generated success plan',
csc__Success_Plan__c.csc__Effective_Date__c => Date.newInstance(2023, 6, 9)
};
final Map<SObjectType, Set<Id>> relatedRecordsIdMap = new Map<SObjectType, Set<Id>>{
csc__Objective__c.sObjectType => new Set<Id>{
'a1GDR000002AzEL2A0',
'a1GDR000002AzEL2B0',
'a1GDR000002AzEL2C0'
},
csc__Playbook__c.sObjectType => new Set<Id>(),
csc__Playbook_Task__c.sObjectType => new Set<Id>()
};
// Set options to be used during processing. Options is an enum datatype that includes the value COPY_CS_SKILLS_FROM_PLAYBOOK and IS_SYNCHRONOUS_PROCESS.
Set<csc.CreateSuccessPlanFromTemplateRequest.Options> options2 = new Set<csc.CreateSuccessPlanFromTemplateRequest.Options>();
// Add COPY_CS_SKILLS_FROM_PLAYBOOK value into the option. It is an enum datatype, if present in the parameter, will copy skills from the playbook.
// If you do not want to copy skills, you can either use the constructor without any options or pass the option without the value COPY_CS_SKILLS_FROM_PLAYBOOK.
options2.add(csc.CreateSuccessPlanFromTemplateRequest.Options.COPY_CS_SKILLS_FROM_PLAYBOOK);
// Add IS_SYNCHRONOUS_PROCESS value into the option. It is an Enum datatype, if present in the parameter, it will run the process synchronously.
// If you want to run the process asynchronously, you can either use the constructor without any options or pass the option without the value IS_SYNCHRONOUS_PROCESS.
options2.add(csc.CreateSuccessPlanFromTemplateRequest.Options.IS_SYNCHRONOUS_PROCESS);
// Note: This service copies all related records from the template to the new success plan. This includes objectives and their respective related records.
// Instantiate an additional request
final csc.CreateSuccessPlanFromTemplateRequest request2 = new csc.CreateSuccessPlanFromTemplateRequest(
templateId2,
fieldsToPopulate2,
relatedRecordsIdMap,
options2
);
requests.add(request2);
// This second request will selectively copy the objectives with the IDs specified, and will omit playbooks and playbook tasks when making the new success plan.
// To copy all related records of a specific type, don't provide a value for that object type in the relatedRecordsIdMap.
// To omit all related records of a specific type, provide an empty list as a value for that object type in the relatedRecordsIdMap.
// Call the service with the list of requests.
final List<csc.CreateSuccessPlanFromTemplateResponse> responses = csc.CreateSuccessPlanFromTemplateService.createSuccessPlansFromTemplates(
requests
);
|