CSC Apex API Developer Reference

csc.CreatePlaybookFromTemplateService

global with sharing class CreatePlaybookFromTemplateService

Used to create playbooks from templates, exposes the global API for mass creation of playbooks from templates.

Methods

createPlaybooksFromTemplates

global static List<csc.CreatePlaybookFromTemplateResponse> createPlaybooksFromTemplates(List<csc.CreatePlaybookFromTemplateRequest> requests)

Used to create multiple playbooks from templates using a list of requests.

Input Parameters

Name Type Description
requests List<csc.CreatePlaybookFromTemplateRequest> The CreatePlaybookFromTemplateRequest objects to be processed.

Return Value

List<CreatePlaybookFromTemplateResponse>

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.CreatePlaybookFromTemplateRequest> requests = new List<csc.CreatePlaybookFromTemplateRequest>();

// Provide the ID of the template that you want to create a playbook from.
final Id templateId1 = 'a2f53000000Fy8TAAS';

// Make a map of fields to populate on the new playbook and values to populate them with.
final Map<SObjectField, Object> fieldsToPopulate1 = new Map<SObjectField, Object>{
    csc__Playbook__c.Name => '1st API-generated playbook',
    csc__Playbook__c.csc__Start_Date__c => Date.newInstance(2023, 5, 8),
    csc__Playbook__c.csc__End_Date__c => Date.newInstance(2023, 8, 10)
};

// Instantiate a request by providing a template ID and a map of fields to populate.
final csc.CreatePlaybookFromTemplateRequest request1 = new csc.CreatePlaybookFromTemplateRequest(
    templateId1,
    fieldsToPopulate1
);
requests.add(request1);

// Prepare parameters for the additional CreatePlaybookFromTemplateRequest instance to be created.
final Id templateId2 = 'a2f53000000Fy8VAAS';
final Map<SObjectField, Object> fieldsToPopulate2 = new Map<SObjectField, Object>{
    csc__Playbook__c.Name => '2nd API-generated playbook',
    csc__Playbook__c.csc__Start_Date__c => Date.newInstance(2023, 6, 9)
};
final Map<SObjectType, Set<Id>> relatedRecordsIdMap = new Map<SObjectType, Set<Id>>{
    csc__Playbook_Task__c.sObjectType => new Set<Id>{
        'a2f53456000Fy8XTYS',
        'a2f53304050Fy8PLSY',
        'a2f53039270Fy8XLUS'
    }
};
// Note: This service copies all related records from the template to the new playbook. This includes playbook tasks, but not playbook task assignments.

// Instantiate an additional request
final csc.CreatePlaybookFromTemplateRequest request2 = new csc.CreatePlaybookFromTemplateRequest(
    templateId2,
    fieldsToPopulate2,
    relatedRecordsIdMap
);
requests.add(request2);

// This second request will selectively copy the tasks with the IDs specified when making the new playbook.
// 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.CreatePlaybookFromTemplateResponse> responses = csc.CreatePlaybookFromTemplateService.createPlaybooksFromTemplates(
    requests
);
© Copyright 2009–2024 Certinia Inc. All rights reserved. Various trademarks held by their respective owners.