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.

1Map<String, Object> input = new Map<String, Object>{'methodName' => 'startProductHierarchyJob'};
2vlocity_cmt.TelcoAdminConsoleController controllerClass = new vlocity_cmt.TelcoAdminConsoleController();
3controllerClass.setParameters(JSON.serialize(input));
4controllerClass.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.

1Map<String, Object> input = new Map<String, Object>{'methodName' => 'clearPlatformCache'};
2vlocity_cmt.TelcoAdminConsoleController controllerClass = new vlocity_cmt.TelcoAdminConsoleController();
3controllerClass.setParameters(JSON.serialize(input));
4controllerClass.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:

1Map<String, Object> input = new Map<String, Object>{'methodName' => 'refreshPriceBook', 'priceBookId' => 'price book ID'};
2vlocity_cmt.TelcoAdminConsoleController controllerClass = new vlocity_cmt.TelcoAdminConsoleController();
3controllerClass.setParameters(JSON.serialize(input));
4controllerClass.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.

1global class ClearCacheBatch implements Database.Batchable<sObject> {
2   public String query = 'SELECT Id FROM vlocity_cmt__CachedAPIResponse__c';
3
4   global Database.QueryLocator start(Database.BatchableContext BC){
5      return Database.getQueryLocator(query);
6   }
7
8   global void execute(Database.BatchableContext BC, List<sObject> scope){
9      delete scope;
10      DataBase.emptyRecycleBin(scope);
11   }
12
13   global void finish(Database.BatchableContext BC){
14   }
15}

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.

1Id 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:

1Map<String, Object> input = new Map<String, Object>{'methodName' => 'refreshBatchJobLists'};
2vlocity_cmt.TelcoAdminConsoleController controllerClass = new vlocity_cmt.TelcoAdminConsoleController();
3controllerClass.setParameters(JSON.serialize(input));
4controllerClass.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:

1Map<String, Object> input = new Map<String, Object>{'methodName' => 'populateCacheCAJob', 'selectedList' => new
2  List<Object>{'ContextEligibilityGenerator'}};
3vlocity_cmt.TelcoAdminConsoleController controllerClass = new vlocity_cmt.TelcoAdminConsoleController();
4controllerClass.setParameters(JSON.serialize(input));
5controllerClass.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.

1Map<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>>{}};
2vlocity_cmt.TelcoAdminConsoleController controllerClass = new vlocity_cmt.TelcoAdminConsoleController();
3controllerClass.setParameters(JSON.serialize(input));
4controllerClass.invokeMethod();

GetOffersHierarchyHelper Job 

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

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

GetOffers Job 

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

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

GetContainsOffers Job 

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

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

GetPrices Job 

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

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

GetOfferDetails Job 

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

1Map<String, Object> input = new Map<String, Object>{'methodName' => 'populateCacheCAJob', 'selectedList' =>
2  new List<Object>{'GetOfferDetails'}};
3vlocity_cmt.TelcoAdminConsoleController controllerClass = new
4  vlocity_cmt.TelcoAdminConsoleController();
5controllerClass.setParameters(JSON.serialize(input));
6controllerClass.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:

1Map<String, Object> input = new Map<String, Object>{new Map<String, Object>{'methodName' => 'populateCacheCAJob',
2 'selectedList' => new List<Object>
3{'GetOfferDetails'},
4'filters'=> new Map<String,List<Object>>{'Catalogs'=> new
5  List<Object>{'a0G0b00000dT45JEAS'}}};
6vlocity_cmt.TelcoAdminConsoleController controllerClass = new
7  vlocity_cmt.TelcoAdminConsoleController();
8controllerClass.setParameters(JSON.serialize(input));
9controllerClass.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.

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