Promotion and Tactic Transfer Customization Use Cases

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.

1global class TacticTransferSaveCust implements System.Callable {
2    global Object call(String action, Map<String, Object> params) {
3    List<cgcloud.RE_TacticTransfer> tacticTransferWrapper = (List<cgcloud.RE_TacticTransfer>) params.get('tacticTransfer');
4    cgcloud__Tactic__c record = (cgcloud__Tactic__c) tacticTransferWrapper[0].getTactic().getRecord();
5
6    if (record.cgcloud__Date_Thru__c != null) {
7    record.cgcloud__Date_Thru__c = record.cgcloud__Date_Thru__c.addDays(1);
8    }
9
10    return tacticTransferWrapper;
11 }
12}

Here’s a sample Apex class that modifies the slogan field of a promotion.

1global class PromotionTransferSaveCust implements System.Callable {
2    global Object call(String action, Map<String, Object> params) {
3String SAVE_HOOK_SUFFIX = ' Slogan hook ';
4// Get the RE_PromotionTransfer instance
5List<cgcloud.RE_PromotionTransfer> promotionTransferWrapperList = (List<cgcloud.RE_PromotionTransfer>) params.get('promotionTransfer');
6        
7for(cgcloud.RE_PromotionTransfer promotionTransferWrapper : promotionTransferWrapperList) {
8    cgcloud__Promotion__c record = (cgcloud__Promotion__c) promotionTransferWrapper.getPromotion().getRecord();
9
10    if (record.cgcloud__Slogan_Language_1__c != null) {
11        record.cgcloud__Slogan_Language_1__c =
12        record.cgcloud__Slogan_Language_1__c + SAVE_HOOK_SUFFIX;
13    }
14}
15
16return promotionTransferWrapperList;
17}
18}

Delete a managed package sObject record

Here’s a sample Apex class that deletes the first tactic from the list of tactics.

1global class TacticTransferSaveCust implements System.Callable {
2    global Object call(String action, Map<String, Object> params) {
3// Get the RE_TacticTransfer instance
4   List<cgcloud.RE_TacticTransfer> tacticTransferWrapper = (List<cgcloud.RE_TacticTransfer>) params.get('tacticTransfer');
5
6// Delete the first Tactic__c SObject
7   cgcloud.RE_TacticTransfer.Record tacticRecordWrapper = tacticTransferWrapper[0].getTactics()[0];
8    if (!tacticRecordWrapper.isDeleted())
9    {
10       // We can also check if the record is new with isNew()
11      tacticRecordWrapper.setIsDeleted(true);
12    }
13    return tacticTransferWrapper;
14 }
15}

Here’s a sample Apex class that deletes the first promotion from the list of promotions.

1global class PromotionTransferSaveCust implements System.Callable {
2    global Object call(String action, Map<String, Object> params) {
3// Get the List of RE_PromotionTransfer instances
4List<cgcloud.RE_PromotionTransfer> promotionTransferWrapperList = (List<cgcloud.RE_PromotionTransfer>) params.get('promotionTransfer');
5
6// Delete the first Promotion__c sObject
7cgcloud.RE_PromotionTransfer.Record promotionRecord = promotionTransferWrapper[0].getPromotion();
8if (!promotionRecord.isDeleted())
9{ 
10     // We can also check if the record is new with isNew()
11    promotionRecord.setIsDeleted(true);
12}
13    return promotionTransferWrapperList;
14 }
15}

Add a custom sObject

Here’s a sample Apex class that adds additional tactic sObject records to a planned promotion that is saved.

1global class TacticTransferSaveCust implements System.Callable {
2    global Object call(String action, Map<String, Object> params) {
3     List<cgcloud.RE_TacticTransfer> tacticTransferWrapper = (List<cgcloud.RE_TacticTransfer>) params.get('tacticTransfer');
4     for (Integer count = 0; count < 2; count++) {
5       cgcloud__Tactic__c newTactic = new cgcloud__Tactic__c();
6       newTactic.cgcloud__Tactic_Template__c = 'a3A8D000000RFbnUAG';
7       newTactic.cgcloud__Date_From__c = Date.newInstance(2023, 9, 9);
8       newTactic.cgcloud__Date_Thru__c = Date.newInstance(2023, 9, 12);
9       newTactic.RecordTypeId = '0128D000002MRKIQA4';
10       newTactic.cgcloud__Promotion__c = 'a2Y8D000000g4kZUAQ';
11       tacticTransferWrapper.add(new cgcloud.RE_TacticTransfer(newTactic));
12   }
13  return tacticTransferWrapper;
14 }
15}

Here’s a sample Apex class that adds a promotion sObject record during the promotion save process.

1global class PromotionTransferSaveCust implements System.Callable {
2    global Object call(String action, Map<String, Object> params) {
3// Get the List of RE_PromotionTransfer instance
4List<cgcloud.RE_PromotionTransfer> promotionTransferWrapperList = (List<cgcloud.RE_PromotionTransfer>) params.get('promotionTransfer');
5
6//Get the first Promotion Record from the wrapper
7cgcloud__Promotion__c record = (cgcloud__Promotion__c) promotionTransferWrapper[0].getPromotion().getRecord();
8
9List<cgcloud__Promotion__c> promotionList = new List<cgcloud__Promotion__c>();
10
11for (Integer count = 0; count < 1; count++) {
12    cgcloud__Promotion__c newPromotion = new cgcloud__Promotion__c();
13    newPromotion.cgcloud__Slogan_Language_1__c = record.cgcloud__Slogan_Language_1__c + count;
14    promotionList.add(newPromotion);
15    newPromotion.cgcloud__Promotion_Template__c = 'a2X8D0000003NHQUA2'; //Update the new promotion with the target Promotion Template
16    newPromotion.cgcloud__Date_From__c = Date.newInstance(2023, 9, 9);
17    newPromotion.cgcloud__Date_Thru__c = Date.newInstance(2023, 9, 12);
18    newPromotion.RecordTypeId = '0128D000002MRKEQA4'; //Update the new promotion with the correct Record Type ID
19    promotionTransferWrapper.add(new cgcloud.RE_PromotionTransfer(newPromotion));
20}
21
22return promotionTransferWrapper; 
23}
24}

The TPM_Promotion class ensures that all the promotion-related sObjects are committed in an all-or-none fashion while encapsulating all operations in a transaction.

Note

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.

1global class TacticTransferSaveCust implements System.Callable {
2    global Object call(String action, Map<String, Object> params) {
3     List<cgcloud.RE_TacticTransfer> tacticProductTransferWrapper = (List<cgcloud.RE_TacticTransfer>) params.get('tacticTransfer');
4     List<cgcloud.RE_TacticTransfer.Record> records = (List<cgcloud.RE_TacticTransfer.Record>) tacticProductTransferWrapper[0].getTacticProducts(); 
5     records[0].setIsDeleted(true);
6     return tacticProductTransferWrapper;
7 }
8}

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.

1global class TacticTransferSaveCust implements System.Callable {
2    global Object call(String action, Map<String, Object> params) {
3    List<cgcloud.RE_TacticTransfer> tacticTransferWrapper = (List<cgcloud.RE_TacticTransfer>) params.get('tacticTransfer');
4    List<cgcloud.RE_TacticTransfer.Record> records = (List<cgcloud.RE_TacticTransfer.Record>) tacticTransferWrapper[0].getTacticProducts();
5    if(records.size()>0){
6      cgcloud__Tactic_Product__c newTacticProduct = new cgcloud__Tactic_Product__c();
7      newTacticProduct.cgcloud__Tactic__c = tacticTransferWrapper[0].getTactic().getId();
8      newTacticProduct.cgcloud__Product__c='01t8D000003vc4aQAA';
9      tacticTransferWrapper[0].addTacticProduct(newTacticProduct);
10    }
11  return tacticTransferWrapper;
12  }
13}