Playbook Customer Success Resource Creation Script

This script automates the creation of Playbook Customer Success Resource records for all your existing Playbooks. It ensures that each playbook, for which an owner is allocated, is not a template and has neither a Cancelled nor Completed status, is properly linked to its dedicated customer success resources, streamlining your operations.

You'll need administrator access to your org to run this script.

Copy
List<String> successPlanStatusToIgnore = new List<String>{'Blocked', 'Completed'}; 
                List<csc__Success_Plan__c> successPlanRecords = [SELECT Id, csc__Success_Plan_Owner__c FROM csc__Success_Plan__c WHERE csc__Is_Template__c = false AND csc__Success_Plan_Owner__c != null AND csc__Status__c NOT IN :successPlanStatusToIgnore AND Id NOT IN (SELECT csc__Success_Plan__c FROM csc__Success_Plan_Customer_Success_Resource__c) LIMIT 10000]; 

                List<csc__Success_Plan_Customer_Success_Resource__c> successPlanCustomserSuccessResourceRecordsToInsert = new List<csc__Success_Plan_Customer_Success_Resource__c>(); 

                for(csc__Success_Plan__c record : successPlanRecords){         
                successPlanCustomserSuccessResourceRecordsToInsert.add(
                new csc__Success_Plan_Customer_Success_Resource__c(        
                csc__Success_Plan__c = record.Id,         
                csc__Resource__c = record.csc__Success_Plan_Owner__c,         
                csc__Start_Date__c = DateWrapper.today(),
                csc__Is_Active__c = true
                )
                );     
                } 

                Assert.isFalse(successPlanCustomserSuccessResourceRecordsToInsert.isEmpty(), 'No Success Plan Customer Success Records to Insert.'); 

                Boolean disableSuccessPlanCSResourceValidation = ResourceManagementDomainContext.disableSuccessPlanCSResourceValidation; 

                ResourceManagementDomainContext.disableSuccessPlanCSResourceValidation = true; 
                insert successPlanCustomserSuccessResourceRecordsToInsert; 
            ResourceManagementDomainContext.disableSuccessPlanCSResourceValidation = disableSuccessPlanCSResourceValidation;