Running Maintenance and Digital Commerce Cache Jobs Remotely

You can run the Maintenance Jobs and the Digital Commerce API cache jobs programmatically by using anonymous Apex code as shown in the following examples.

Product Hierarchy Maintenance

Use this anonymous Apex job to build a streamlined version of the product hierarchies in the Data Store subjects. This is the same result as using Vlocity CMT Administration > Maintenance Jobs > Product Hierarchy Maintenance.

Map<String, Object> input = new Map<String, Object>{'methodName' => 'startProductHierarchyJob'};
vlocity_cmt.TelcoAdminConsoleController controllerClass = new vlocity_cmt.TelcoAdminConsoleController();
controllerClass.setParameters(JSON.serialize(input));
controllerClass.invokeMethod();

Clear Managed Platform Cache

Use this anonymous Apex job to clear the org cache in the CPQPartition platform cache. This is the same result as using Vlocity CMT Administration > Maintenance Jobs > Clear Managed Platform Cache.

Map<String, Object> input = new Map<String, Object>{'methodName' => 'clearPlatformCache'};
vlocity_cmt.TelcoAdminConsoleController controllerClass = new vlocity_cmt.TelcoAdminConsoleController();
controllerClass.setParameters(JSON.serialize(input));
controllerClass.invokeMethod();

Refresh Platform Cache (Full)

Use this anonymous Apex job to copy product hierarchy data to the platform cache and to rebuild the product attribute cache. This is the same result as using Vlocity CMT Administration > Maintenance Jobs > Refresh Platform Cache (Full).

Note that you must include the appropriate Pricebook2 ID in the script shown here:

Map<String, Object> input = new Map<String, Object>{'methodName' => 'refreshPriceBook', 'priceBookId' => 'price book ID'};
vlocity_cmt.TelcoAdminConsoleController controllerClass = new vlocity_cmt.TelcoAdminConsoleController();
controllerClass.setParameters(JSON.serialize(input));
controllerClass.invokeMethod();

ClearCacheBatch

Copy and paste the following Apex class into your org. This is a batch job that clears the cache. Use this if you have a large catalog or many context dimensions that result in a cache of 50k+ records.

global class ClearCacheBatch implements Database.Batchable<sObject> {
   public String query = 'SELECT Id FROM vlocity_cmt__CachedAPIResponse__c';

   global Database.QueryLocator start(Database.BatchableContext BC){
      return Database.getQueryLocator(query);
   }

   global void execute(Database.BatchableContext BC, List<sObject> scope){
      delete scope;
      DataBase.emptyRecycleBin(scope);
   }

   global void finish(Database.BatchableContext BC){
   }
}

Clear Cache

You can fully clear the Digital Commerce API cache with the following anonymous Apex. Use it to debug and troubleshoot failures with the Digital Commerce APIs.

Id batchInstanceId = Database.executeBatch(new ClearCacheBatch());

Check Job Status

Use this anonymous Apex job to check a jobs' status. This is critical as the jobs can take a long time to run if you have a large catalog. Here is the anonymous apex for it:

Map<String, Object> input = new Map<String, Object>{'methodName' => 'refreshBatchJobLists'};
vlocity_cmt.TelcoAdminConsoleController controllerClass = new vlocity_cmt.TelcoAdminConsoleController();
controllerClass.setParameters(JSON.serialize(input));
controllerClass.invokeMethod();

ContextEligibilityGenerator Job

This job populates the cache with the eligible offers for individual context combinations. The data is used by the GetOffers and GetContainOffers jobs.

You can run the job using anonymous apex code as shown here:

Map<String, Object> input = new Map<String, Object>{'methodName' => 'populateCacheCAJob', 'selectedList' => new
  List<Object>{'ContextEligibilityGenerator'}};
vlocity_cmt.TelcoAdminConsoleController controllerClass = new vlocity_cmt.TelcoAdminConsoleController();
controllerClass.setParameters(JSON.serialize(input));
controllerClass.invokeMethod();

Generate Full Cache

Use this job to generate, or populate, a full cache. This is the same result as using Vlocity CMT Administration > Cacheable API Jobs > Populate API Cache and selecting all of the jobs and catalogs.

Map<String, Object> input = new Map<String, Object>{'methodName' => 'populateCacheCAJob','selectedList' => new List<Object>{'ContextEligibilityGenerator','GetOffersHierarchyHelper','GetOffers','GetContainOffers','GetPrices','GetOfferDetails'},'filters'=> new Map<String,List<Object>>{}};
vlocity_cmt.TelcoAdminConsoleController controllerClass = new vlocity_cmt.TelcoAdminConsoleController();
controllerClass.setParameters(JSON.serialize(input));
controllerClass.invokeMethod();

GetOffersHierarchyHelper Job

This job populates the cache with the hierarchy of bundles. The data is used in the GetOfferDetails Job.

Map<String, Object> input = new Map<String, Object>{'methodName' => 'populateCacheCAJob', 'selectedList' => new
  List<Object>{'GetOffersHierarchyHelper'}};
vlocity_cmt.TelcoAdminConsoleController controllerClass = new vlocity_cmt.TelcoAdminConsoleController();
controllerClass.setParameters(JSON.serialize(input));
controllerClass.invokeMethod();

GetOffers Job

This job populates the cache with the list of offers for individual context combinations.

Map<String, Object> input = new Map<String, Object>{'methodName' => 'populateCacheCAJob', 'selectedList' => new
  List<Object>{'GetOffers'}};
vlocity_cmt.TelcoAdminConsoleController controllerClass = new vlocity_cmt.TelcoAdminConsoleController();
controllerClass.setParameters(JSON.serialize(input));
controllerClass.invokeMethod();

GetContainsOffers Job

This job populates the cache with the parent offers for individual offers.

Map<String, Object> input = new Map<String, Object>{'methodName' => 'populateCacheCAJob', 'selectedList' => new
  List<Object>{'GetContainOffers'}};
vlocity_cmt.TelcoAdminConsoleController controllerClass = new vlocity_cmt.TelcoAdminConsoleController();
controllerClass.setParameters(JSON.serialize(input));
controllerClass.invokeMethod();

GetPrices Job

This job populates the cache with the prices of products. This is used in GetOffers, GetContainsOffers and GetOfferDetails jobs.

Map<String, Object> input = new Map<String, Object>{'methodName' => 'populateCacheCAJob', 'selectedList' => new
  List<Object>{'GetPrices'}};
vlocity_cmt.TelcoAdminConsoleController controllerClass = new vlocity_cmt.TelcoAdminConsoleController();
controllerClass.setParameters(JSON.serialize(input));
controllerClass.invokeMethod();

GetOfferDetails Job

This job populates the cache with the details of individual offers (product or promotion).

Map<String, Object> input = new Map<String, Object>{'methodName' => 'populateCacheCAJob', 'selectedList' =>
  new List<Object>{'GetOfferDetails'}};
vlocity_cmt.TelcoAdminConsoleController controllerClass = new
  vlocity_cmt.TelcoAdminConsoleController();
controllerClass.setParameters(JSON.serialize(input));
controllerClass.invokeMethod();

Generating the Cache for Specific Catalogs

You can run any of the batch jobs from anonymous Apex code by specifying the ID of the catalog. In the following example, the ID of the catalog is a0G0b00000dT45JEAS:

Map<String, Object> input = new Map<String, Object>{new Map<String, Object>{'methodName' => 'populateCacheCAJob',
 'selectedList' => new List<Object>
{'GetOfferDetails'},
'filters'=> new Map<String,List<Object>>{'Catalogs'=> new
  List<Object>{'a0G0b00000dT45JEAS'}}};
vlocity_cmt.TelcoAdminConsoleController controllerClass = new
  vlocity_cmt.TelcoAdminConsoleController();
controllerClass.setParameters(JSON.serialize(input));
controllerClass.invokeMethod();

Regenerate Cached API Records

Run this job to regenerate cached API records. If the catalog has been modified, this job regenerates the cached API response objects based on the modified sales catalog and product models.

Map<String, Object> input = new Map<String, Object>{'methodName' => 'regenerateCacheAPIRecordsJobs'};
vlocity_cmt.TelcoAdminConsoleController controllerClass = new
  vlocity_cmt.TelcoAdminConsoleController();
controllerClass.setParameters(JSON.serialize(input));
controllerClass.invokeMethod();