This job regenerates the JSON Attribute fields for products managed through Vlocity Product Console. For products that are managed in Product Console, you can run this batch job in case the JSONAttribute gets out-of-sync with the attributes that are assigned to the product.
First get a list of Product2 Ids, prodIds, then call the batch job.
Execute this code in the Exectue Anonymous window in the Developer Console.
Map<Id,Product2> products = new Map<Id,Product2>([SELECT Id FROM Product2]);
List<Id> productIds = new List<Id>(products.keySet());
Database.executeBatch(new vlocity_cmt.EPCProductAttribJSONBatchJob (productIds), 1);
|
Applies to |
Summer '17 and later |
|---|---|
|
Apex Name |
EPCProductAttribJSONBatchJob |
|
Where to Run this Job |
Developer Console |
|
Risks of Running This Job |
None |
|
When Not to Run This Job |
Do not run this job In a live production environment when orders are being taken. Do not run this job in orgs with products created using the Salesforce Classic interface instead of Vlocity Product Console. |
|
When to Run This Job |
|
|
More Information |
The EPCProductAttribJSONBatchJob processes products attributes created with Vlocity Product Console and corrects the product attribute record IDs. It does not affect the org cache. It replaces the FixProductAttribJSONBatchJob used prior to the ​Salesforce Industries Communications, Media, and Energy Summer ’17 release. For more information, see Fix Product Attribute JSON. |
Troubleshooting
If you update a picklist item, before you update the AttributeMetadata__c or JSONAttribute__c feilds, run this batch job to update the AttributeAssignment used by the EPCProductAttribJSONBatchJob.
global class UpdateAttributeAssignment implements Database.Batchable<sObject>
{
String query;
String attrId;
String namespace = 'vlocity_cmt__';
global UpdateAttributeAssignment(String attributeId)
{
attrId = attributeId;
}
global Database.QueryLocator start(Database.BatchableContext BC)
{
query = 'Select Id, ' +
namespace + 'AttributeCategoryId__c ,' +
namespace + 'AttributeId__c ,' +
namespace + 'AttributeUniqueCode__c ,' +
namespace + 'IsActive__c ,' +
namespace + 'IsDynamic__c ,' +
namespace + 'ObjectId__c ,' +
namespace + 'ObjectLink__c ,' +
namespace + 'ObjectType__c ,' +
namespace + 'RemovedFlag__c ,' +
namespace + 'ValueDescription__c ,' +
namespace + 'AttributeCloneable__c ,' +
namespace + 'AttributeConfigurable__c ,' +
namespace + 'AttributeDisplayNameOverride__c ,' +
namespace + 'AttributeDisplayName__c ,' +
namespace + 'AttributeDisplaySequence__c ,' +
namespace + 'AttributeFilterable__c ,' +
namespace + 'AttributeName__c ,' +
namespace + 'CategoryCode__c ,' +
namespace + 'CategoryDisplaySequence__c ,' +
namespace + 'CategoryName__c ,' +
namespace + 'DisplaySequence__c ,' +
namespace + 'HasRule__c ,' +
namespace + 'IsActiveAssignment__c ,' +
namespace + 'IsConfigurable__c ,' +
namespace + 'IsHidden__c ,' +
namespace + 'IsOverride__c ,' +
namespace + 'IsQueryDriven__c ,' +
namespace + 'IsReadOnly__c ,' +
namespace + 'IsRequired__c ,' +
namespace + 'PicklistId__c ,' +
namespace + 'UIDisplayType__c ,' +
namespace + 'ValidValuesData__c ,' +
namespace + 'ValueDataType__c ,' +
namespace + 'GlobalKey__c ,' +
namespace + 'IsEncrypted__c ,' +
namespace + 'IsNotAssetizable__c ,' +
namespace + 'IsNotTranslatable__c ' +
'From ' + namespace + 'AttributeAssignment__c Where ' + namespace + 'AttributeId__c = :attrId';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject> scope)
{
List<vlocity_cmt__AttributeAssignment__c> aaList = (List<vlocity_cmt__AttributeAssignment__c>) scope;
List<Id> productIdList = new List<Id>();
for (vlocity_cmt__AttributeAssignment__c aa: aaList)
{
Map<String, Object> inputs = new Map<String, Object>();
inputs.put('so', aa);
Object result = vlocity_cmt.ProductConsoleControllerV2.invokeMethod('saveAttributeAssignment', JSON.serialize(inputs));
}
}
global void finish(Database.BatchableContext BC)
{
}
}
- In the Developer Console, create a new file and name it UpdateAttributeAssignment.cls.
- Copy and paste the code into this file.
- In the Developer Console's Anonymous Apex window, execute this code, replacing
<attribute_id> with the actual ID of the attribute associated with the picklist
item you
updated.
Database.executeBatch(new UpdateAttributeAssignment ('<attributeId>'), 1); - Regenerate AttributeMetadata by running EPCProductAttribJSONBatchJob.