CSC Apex API Developer Reference

csc.CreateObjectiveFromTemplateService

global with sharing class CreateObjectiveFromTemplateService

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

Methods

createObjectivesFromTemplates

global static List<csc.CreateObjectiveFromTemplateResponse> createObjectivesFromTemplates(List<csc.CreateObjectiveFromTemplateRequest> requests)

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

Input Parameters

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

Return Value

List<CreateObjectiveFromTemplateResponse>

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

// Provide the ID of the template that you want to create an objective from.
final Id templateId1 = 'a1GDR000002AzEL2A0';

// Make a map of fields to populate on the new objective and values to populate them with.
final Map<SObjectField, Object> fieldsToPopulate1 = new Map<SObjectField, Object>{
    csc__Objective__c.Name => '1st API-generated objective',
    csc__Objective__c.csc__Start_Date__c => Date.newInstance(2023, 5, 8),
    csc__Objective__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.CreateObjectiveFromTemplateRequest request1 = new csc.CreateObjectiveFromTemplateRequest(
    templateId1,
    fieldsToPopulate1
);
requests.add(request1);

// Prepare parameters for the additional CreateObjectiveFromTemplateRequest instance to be created.
final Id templateId2 = 'a1GDR000002AzEQ2A0';
final Map<SObjectField, Object> fieldsToPopulate2 = new Map<SObjectField, Object>{
    csc__Objective__c.Name => '2nd API-generated objective',
    csc__Objective__c.csc__Start_Date__c => Date.newInstance(2023, 6, 9)
};
final Map<SObjectType, Set<Id>> relatedRecordsIdMap = new Map<SObjectType, Set<Id>>{
    csc__Playbook__c.sObjectType => new Set<Id>{
        'a1KDR000003VWx52AG',
        'a1KDR000003VWx52BG',
        'a1KDR000003VWx52CG'
    },
    csc__Playbook_Task__c.sObjectType => new Set<Id>()
};
// Note: This service copies all related records from the template to the new objective. This includes playbooks and their respective related records.

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

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