CSC Apex API Developer Reference

csc.CreateSuccessPlanFromTemplateService

global with sharing class CreateSuccessPlanFromTemplateService

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

Methods

createSuccessPlansFromTemplates

global static List<csc.CreateSuccessPlanFromTemplateResponse> createSuccessPlansFromTemplates(List<csc.CreateSuccessPlanFromTemplateRequest> requests)

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

Input Parameters

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

Return Value

List<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)
};

// Instantiate a request by providing a template ID and a map of fields to populate.
final csc.CreateSuccessPlanFromTemplateRequest request1 = new csc.CreateSuccessPlanFromTemplateRequest(
    templateId1,
    fieldsToPopulate1
);
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>()
};
// 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
);
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
);
© Copyright 2009–2023 Certinia Inc. All rights reserved. Various trademarks held by their respective owners.