This section provides different Apex customization use cases for the promotion and
tactic transfer process.
Change a managed package sObject field value
Here’s a sample Apex class that modifies the date field of a tactic.
global class TacticTransferSaveCust implements System.Callable {
global Object call(String action, Map<String, Object> params) {
List<cgcloud.RE_TacticTransfer> tacticTransferWrapper = (List<cgcloud.RE_TacticTransfer>) params.get('tacticTransfer');
cgcloud__Tactic__c record = (cgcloud__Tactic__c) tacticTransferWrapper[0].getTactic().getRecord();
if (record.cgcloud__Date_Thru__c != null) {
record.cgcloud__Date_Thru__c = record.cgcloud__Date_Thru__c.addDays(1);
}
return tacticTransferWrapper;
}
}
Here’s a sample Apex class that modifies the slogan field of a promotion.
global class PromotionTransferSaveCust implements System.Callable {
global Object call(String action, Map<String, Object> params) {
String SAVE_HOOK_SUFFIX = ' Slogan hook ';
// Get the RE_PromotionTransfer instance
List<cgcloud.RE_PromotionTransfer> promotionTransferWrapperList = (List<cgcloud.RE_PromotionTransfer>) params.get('promotionTransfer');
for(cgcloud.RE_PromotionTransfer promotionTransferWrapper : promotionTransferWrapperList) {
cgcloud__Promotion__c record = (cgcloud__Promotion__c) promotionTransferWrapper.getPromotion().getRecord();
if (record.cgcloud__Slogan_Language_1__c != null) {
record.cgcloud__Slogan_Language_1__c =
record.cgcloud__Slogan_Language_1__c + SAVE_HOOK_SUFFIX;
}
}
return promotionTransferWrapperList;
}
}
Delete a managed package sObject record
Here’s a sample Apex class that deletes the first tactic from the list of tactics.
global class TacticTransferSaveCust implements System.Callable {
global Object call(String action, Map<String, Object> params) {
// Get the RE_TacticTransfer instance
List<cgcloud.RE_TacticTransfer> tacticTransferWrapper = (List<cgcloud.RE_TacticTransfer>) params.get('tacticTransfer');
// Delete the first Tactic__c SObject
cgcloud.RE_TacticTransfer.Record tacticRecordWrapper = tacticTransferWrapper[0].getTactics()[0];
if (!tacticRecordWrapper.isDeleted())
{
// We can also check if the record is new with isNew()
tacticRecordWrapper.setIsDeleted(true);
}
return tacticTransferWrapper;
}
}
Here’s a sample Apex class that deletes the first promotion from the list of promotions.
global class PromotionTransferSaveCust implements System.Callable {
global Object call(String action, Map<String, Object> params) {
// Get the List of RE_PromotionTransfer instances
List<cgcloud.RE_PromotionTransfer> promotionTransferWrapperList = (List<cgcloud.RE_PromotionTransfer>) params.get('promotionTransfer');
// Delete the first Promotion__c sObject
cgcloud.RE_PromotionTransfer.Record promotionRecord = promotionTransferWrapper[0].getPromotion();
if (!promotionRecord.isDeleted())
{
// We can also check if the record is new with isNew()
promotionRecord.setIsDeleted(true);
}
return promotionTransferWrapperList;
}
}
Add a custom sObject
Here’s a sample Apex class that adds additional tactic sObject records to a planned promotion that is saved.
global class TacticTransferSaveCust implements System.Callable {
global Object call(String action, Map<String, Object> params) {
List<cgcloud.RE_TacticTransfer> tacticTransferWrapper = (List<cgcloud.RE_TacticTransfer>) params.get('tacticTransfer');
for (Integer count = 0; count < 2; count++) {
cgcloud__Tactic__c newTactic = new cgcloud__Tactic__c();
newTactic.cgcloud__Tactic_Template__c = 'a3A8D000000RFbnUAG';
newTactic.cgcloud__Date_From__c = Date.newInstance(2023, 9, 9);
newTactic.cgcloud__Date_Thru__c = Date.newInstance(2023, 9, 12);
newTactic.RecordTypeId = '0128D000002MRKIQA4';
newTactic.cgcloud__Promotion__c = 'a2Y8D000000g4kZUAQ';
tacticTransferWrapper.add(new cgcloud.RE_TacticTransfer(newTactic));
}
return tacticTransferWrapper;
}
}
Here’s a sample Apex class that adds a promotion sObject record during the promotion save process.
global class PromotionTransferSaveCust implements System.Callable {
global Object call(String action, Map<String, Object> params) {
// Get the List of RE_PromotionTransfer instance
List<cgcloud.RE_PromotionTransfer> promotionTransferWrapperList = (List<cgcloud.RE_PromotionTransfer>) params.get('promotionTransfer');
//Get the first Promotion Record from the wrapper
cgcloud__Promotion__c record = (cgcloud__Promotion__c) promotionTransferWrapper[0].getPromotion().getRecord();
List<cgcloud__Promotion__c> promotionList = new List<cgcloud__Promotion__c>();
for (Integer count = 0; count < 1; count++) {
cgcloud__Promotion__c newPromotion = new cgcloud__Promotion__c();
newPromotion.cgcloud__Slogan_Language_1__c = record.cgcloud__Slogan_Language_1__c + count;
promotionList.add(newPromotion);
newPromotion.cgcloud__Promotion_Template__c = 'a2X8D0000003NHQUA2'; //Update the new promotion with the target Promotion Template
newPromotion.cgcloud__Date_From__c = Date.newInstance(2023, 9, 9);
newPromotion.cgcloud__Date_Thru__c = Date.newInstance(2023, 9, 12);
newPromotion.RecordTypeId = '0128D000002MRKEQA4'; //Update the new promotion with the correct Record Type ID
promotionTransferWrapper.add(new cgcloud.RE_PromotionTransfer(newPromotion));
}
return promotionTransferWrapper;
}
}
Get the tactic products linked to a tactic, and perform customization on the tactic products
Here’s a sample Apex class that gets all the products linked to a tactic and deletes the first product in the list.
global class TacticTransferSaveCust implements System.Callable {
global Object call(String action, Map<String, Object> params) {
List<cgcloud.RE_TacticTransfer> tacticProductTransferWrapper = (List<cgcloud.RE_TacticTransfer>) params.get('tacticTransfer');
List<cgcloud.RE_TacticTransfer.Record> records = (List<cgcloud.RE_TacticTransfer.Record>) tacticProductTransferWrapper[0].getTacticProducts();
records[0].setIsDeleted(true);
return tacticProductTransferWrapper;
}
}
Add new tactic products to the existing managed package or new tactic records
Here’s a sample Apex class that adds a product to a specific tactic.
global class TacticTransferSaveCust implements System.Callable {
global Object call(String action, Map<String, Object> params) {
List<cgcloud.RE_TacticTransfer> tacticTransferWrapper = (List<cgcloud.RE_TacticTransfer>) params.get('tacticTransfer');
List<cgcloud.RE_TacticTransfer.Record> records = (List<cgcloud.RE_TacticTransfer.Record>) tacticTransferWrapper[0].getTacticProducts();
if(records.size()>0){
cgcloud__Tactic_Product__c newTacticProduct = new cgcloud__Tactic_Product__c();
newTacticProduct.cgcloud__Tactic__c = tacticTransferWrapper[0].getTactic().getId();
newTacticProduct.cgcloud__Product__c='01t8D000003vc4aQAA';
tacticTransferWrapper[0].addTacticProduct(newTacticProduct);
}
return tacticTransferWrapper;
}
}