Promotion and Tactic Transfer Customization Use Cases
This Page
All Documentation
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();56 if (record.cgcloud__Date_Thru__c != null) {7 record.cgcloud__Date_Thru__c = record.cgcloud__Date_Thru__c.addDays(1);8 }910 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 instance5List<cgcloud.RE_PromotionTransfer> promotionTransferWrapperList = (List<cgcloud.RE_PromotionTransfer>) params.get('promotionTransfer');67for(cgcloud.RE_PromotionTransfer promotionTransferWrapper : promotionTransferWrapperList) {8 cgcloud__Promotion__c record = (cgcloud__Promotion__c) promotionTransferWrapper.getPromotion().getRecord();910 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}1516return 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 instance4 List<cgcloud.RE_TacticTransfer> tacticTransferWrapper = (List<cgcloud.RE_TacticTransfer>) params.get('tacticTransfer');56// Delete the first Tactic__c SObject7 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 instances4List<cgcloud.RE_PromotionTransfer> promotionTransferWrapperList = (List<cgcloud.RE_PromotionTransfer>) params.get('promotionTransfer');56// Delete the first Promotion__c sObject7cgcloud.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.
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 instance4List<cgcloud.RE_PromotionTransfer> promotionTransferWrapperList = (List<cgcloud.RE_PromotionTransfer>) params.get('promotionTransfer');56//Get the first Promotion Record from the wrapper7cgcloud__Promotion__c record = (cgcloud__Promotion__c) promotionTransferWrapper[0].getPromotion().getRecord();89List<cgcloud__Promotion__c> promotionList = new List<cgcloud__Promotion__c>();1011for (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 Template16 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 ID19 promotionTransferWrapper.add(new cgcloud.RE_PromotionTransfer(newPromotion));20}2122return 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}