Loading
透過 Salesforce Scheduler 管理約會
為以容量為基礎的排程更新您的排班工作主題

為以容量為基礎的排程更新您的排班工作主題

透過更新排班工作主題,讓您的組織做好以容量為基礎的排程。

必要版本

提供版本:Lightning Experience。
提供版本:EnterpriseUnlimited Edition
需要的使用者權限
執行指令檔:

已啟用 API

檢視所有資料

Author Apex

檢查您的組織是否有任何排班工作主題且已透過這些指令檔啟用「所有主題支援」核取方塊。針對這類排班工作主題,指令檔會將其刪除,然後為所有工作類型或工作類型群組建立個別排班工作主題。

  1. 根據您組織中的 Scheduler for Health Cloud 設定,複製下列其中一個指令檔。
    • 已停用
      global class BatchProcessShiftWorkTerritory implements Database.Batchable<SObject> {
        global Database.QueryLocator start(Database.BatchableContext BC) {
          return Database.getQueryLocator(
            [SELECT Id FROM Shift ]
          );
        }
      
        global void execute(Database.BatchableContext BC, List<SObject> scope) {
          List<String> shiftIds = new List<String>();
      
          for (Shift shift : (List<Shift>) scope) {
            shiftIds.add(shift.Id);
          }
      
          List<ShiftWorkTopic> shiftWorkTopicsWithAllTopicsSupported = [
            SELECT Id, ShiftId, WorkTypeGroupId
            FROM ShiftWorkTopic
            WHERE AreAllTopicsSupported = TRUE AND ShiftId IN :shiftIds
          ];
      
          List<ShiftWorkTopic> shiftWorkTopicsWithAllTopicsNotSupported = [
            SELECT WorkTypeGroupId, ShiftId
            FROM ShiftWorkTopic
            WHERE AreAllTopicsSupported = FALSE AND ShiftId IN :shiftIds
          ];
      
          List<ShiftWorkTopic> newShiftWorkTopics = new List<ShiftWorkTopic>();
      
          List<WorkTypeGroup> allWorkTypeGroups = [
            SELECT Id
            FROM WorkTypeGroup
          ];
      
          Set<Set<String>> allCombinationsOfWorkTypeGroupAndShift = new Set<Set<String>>();
      
          for (ShiftWorkTopic swt : shiftWorkTopicsWithAllTopicsNotSupported) {
            allCombinationsOfWorkTypeGroupAndShift.add(
              new Set<String>{ swt.WorkTypeGroupId, swt.ShiftId }
            );
          }
      
          // Loop through enabled ShiftWorkTopics and all WorkTypeGroups
            for (
              ShiftWorkTopic enabledTopic : shiftWorkTopicsWithAllTopicsSupported
            ) {
              for (WorkTypeGroup workTypeGroup : allWorkTypeGroups) {
                if (
                  !allCombinationsOfWorkTypeGroupAndShift.contains(
                    new Set<String>{ workTypeGroup.Id, enabledTopic.ShiftId }
                  )
                ) {
                  newShiftWorkTopics.add(
                    new ShiftWorkTopic(
                      WorkTypeGroupId = workTypeGroup.Id,
                      ShiftId = enabledTopic.ShiftId
                    )
                  );
                } 
              }
            }
          
      
          // Insert the new ShiftWorkTopic records
          insert newShiftWorkTopics;
      
          // Delete the enabled ShiftWorkTopics
          delete shiftWorkTopicsWithAllTopicsSupported;
        }
      
        global void finish(Database.BatchableContext BC) {
          // Send notification or log the completion
          System.debug('Batch job completed successfully.');
        }
      }
    • 已啟用
      global class BatchProcessShiftWorkTerritory implements Database.Batchable<SObject> {
        global Database.QueryLocator start(Database.BatchableContext BC) {
          return Database.getQueryLocator(
            [SELECT Id FROM Shift ]
          );
        }
      
        global void execute(Database.BatchableContext BC, List<SObject> scope) {
          List<String> shiftIds = new List<String>();
       
          for (Shift shift : (List<Shift>) scope) {
            shiftIds.add(shift.Id);
          }
      
          List<ShiftWorkTopic> shiftWorkTopicsWithAllTopicsSupported = [
            SELECT Id, ShiftId, WorkTypeId
            FROM ShiftWorkTopic
            WHERE AreAllTopicsSupported = TRUE AND ShiftId IN :shiftIds
          ];
      
          List<ShiftWorkTopic> shiftWorkTopicsWithAllTopicsNotSupported = [
            SELECT WorkTypeId, ShiftId
            FROM ShiftWorkTopic
            WHERE AreAllTopicsSupported = FALSE AND ShiftId IN :shiftIds
          ];
      
          List<ShiftWorkTopic> newShiftWorkTopics = new List<ShiftWorkTopic>();
      
          List<WorkType> allWorkTypes = [
            SELECT Id
            FROM WorkType
          ];
      
          Set<Set<String>> allCombinationsOfWorkTypeAndShift = new Set<Set<String>>();
      
          for (ShiftWorkTopic swt : shiftWorkTopicsWithAllTopicsNotSupported) {
            allCombinationsOfWorkTypeAndShift.add(
              new Set<String>{ swt.WorkTypeId, swt.ShiftId }
            );
          }
      
          // Loop through enabled ShiftWorkTopics and all WorkTypes
            for (
              ShiftWorkTopic enabledTopic : shiftWorkTopicsWithAllTopicsSupported
            ) {
      
              for (WorkType workType : allWorkTypes) {
                if (
                  !allCombinationsOfWorkTypeAndShift.contains(
                    new Set<String>{ workType.Id, enabledTopic.ShiftId }
                  )
                ) {
                  newShiftWorkTopics.add(
                    new ShiftWorkTopic(
                      WorkTypeId = workType.Id,
                      ShiftId = enabledTopic.ShiftId
                    )
                  );
                } 
              }
            }
      
          insert newShiftWorkTopics;
          
          delete shiftWorkTopicsWithAllTopicsSupported;
        }
      
        global void finish(Database.BatchableContext BC) {
          // Send notification or log the completion
          System.debug('Batch job completed successfully.');
        }
      }
  2. 建立名為 BatchProcessShiftWorkTerritory 的 Apex 類別以觸發批准工作流程。請參閱定義 Apex 類別
  3. 進入「設定」,選取「開發人員主控台」。
  4. 在「開發人員主控台」中,按一下「除錯」,然後按一下「開啟執行匿名視窗」。
  5. 執行此程式碼。
    BatchProcessShiftWorkTerritory batchJob = new BatchProcessShiftWorkTerritory(); 
    Integer batchSize = 100; 
    Database.executeBatch(batchJob, batchSize);
  6. 若要檢視指令檔的進度,請進入「設定」,尋找並選取「Apex 工作」。
 
正在載入
Salesforce Help | Article