TPM_RTRReportingParentPromoFilter

Sample of the TPM_RTRReportingParentPromoFilter class.

1public with sharing class TPM_RTRReportingParentPromoFilter implements System.Callable {
2public class TPM_RTRPromotionsCallableException extends Exception {}
3private static List<User> users = [SELECT cgcloud__Sales_Org__c FROM User WHERE Id = :String.escapeSingleQuotes(UserInfo.getUserId()) LIMIT 1];
4private static String userSalesOrgName = users[0].cgcloud__Sales_Org__c;
  1. Create a new list that you can later use to store the value of results = List<Map<String, Object>>.

    1@TestVisible private static List<Map<String, Object>> getParentPromotion() {
    2List<Map<String, Object>> result = new List<Map<String, Object>>();
  2. Query the Promotion object on all records templates that have the CustomerEvents picklist value selected on the TPM_Promo_Type_ControlView__c field for the appropriate sales org ad user.

    1List<cgcloud__Promotion__c> prmTmpl = [SELECT ID, Name, cgcloud__Slogan__c , cgcloud__Anchor_Account__c,cgcloud__Anchor_Account__r.Name,cgcloud__Promotion_Template__r.cgcloud__Description__c,cgcloud__Promotion_Template__r.cgcloud__Sales_Org__c,cgcloud__Promotion_Template__r.TPM_Promo_Type_ControlView__c FROM cgcloud__Promotion__c WHERE cgcloud__Promotion_Template__r.TPM_Promo_Type_ControlView__c ='CustomerEvent' and cgcloud__Promotion_Template__r.cgcloud__Sales_Org__c =: userSalesOrgName ];
    2Map<ID, String> outP = New Map<ID, String>();
    3for(cgcloud__Promotion__c templ : prmTmpl){
    4If(!outP.containsKey(templ.ID)){
    5outP.put(String.valueOf(templ.Id), String.valueOf(templ. cgcloud__Slogan__c));
    6}
    7}
  3. Return the list.

    1for(String statusTo : outP.keyset()){
    2result.add(new Map<String, Object> {
    3'label' => outP.get(statusTo),
    4'value' => statusTo
    5});
    6}
    7system.debug(json.serialize(result));
    8return result;
    9}
    10public Object call(String method, Map<String, Object> args) {
    11return getParentPromotion();
    12}
    13}