Use Case: Fixed Funds

In this use case, the custom datasource is used to include a fixed fund KPI in Real Time Report (RTR). As a result, the fixed funds are aggregated on both category and brand levels. One visualization option is this report, in which a brand value is only available for one brand. However, this value is not summed up to the category level. For the calculation of category levels, the data that’s stored on Salesforce and Processing Services is used.

Prerequisites 

  1. Create a KPI definition for the fund amount. For this KPI definition, ensure that the object scope is Account and it has the writeback feature enabled.

    This KPI definition only provides a name for the external KPI. The Apex class defines how to enter values in this KPI.

    Note

  2. Enter the name of the datasource table as Account Measure.

  3. Add the KPI to the Reporting KPI set that’s used in the report.

Report Configuration 

  1. Create new KPI definitions for each use case, such as Fixed RDF Brand. Ensure that the object scope of these KPI definitions is Account.

  2. Enter the name of the datasource table as Account Measure.

  3. Define these KPI definitions in the report configuration

  4. Create a custom metadata type, TPM_RTRRouting__mdt, which is linked to the KPI definition, sales organization, fund template, and KPI levels.

    Field API NameTypeDescription
    Fund_Template__cTextDetermines the KPI to which the fixed funds are to be attributed. For example, All Transaction Row Records, in which the target fund has the RDF Brand Fund that belongs to the Fixed RDF KPI.
    KPI_Definition__cTextName of the Fixed Funds KPI (such as FXDR and FTDR) that determines the data which should be returned from the logic in the Apex class.
    KPI_Level__cTextFixed funds can be stored on different levels (currently, category and brand). This is needed to determine the method that should be run. (category and brand use different logic.)
    Sales_Org__cTextSales organization to which the record belongs.
  5. On the cgcloud__Fund_Transaction_Row__c object, add a new field.

    Field API NameTypeDescriptionFormula
    TPM_RTRAmount__cFormula (Double)Fixed Funds for Brands are calculated based on the value of the Amount field on the transaction record. Depending on the transaction type (withdraw or deposit), the sum of the aggregated amounts either increases (deposit) or decreases (withdraw).
    The formula field turns the amounts of records with transaction type = deposit to negative values. Instead of aggregating the amount field, you can aggregate the TPM_RTR_Amount__c field.
    IF(ISPICKVAL( cgcloud__Transaction_Type__c , ‘Withdraw’), cgcloud__Amount__c * (-1), cgcloud__Amount__c )
  6. On the cgcloud__Fund_Transaction_Header__c object, add a new field.

    Field API NameTypeDescription
    TPM_Product__cLookup(Product)Used to link products to the Multi-Fund Transaction object.
  7. On the cgcloud__Fund_Template__c object, add a new field.

    Field API NameTypeDescription
    TPM_RTRRoutingFundType__cPicklistUsed to filter fund template records. The picklist values of this field are fund template record names.

    Ensure that you create new fund templates for each case, such as RDF Brand Fund. Maintain the newly created TPM_RTRRoutingFundType__c field on the fund template.

    Note

Apex Classes 

Custom data sources are related to two base Apex classes. Because all reports share these classes, you can use both classes only for code-routing, not to perform any actual logic, queries, or calculations.

In RTR, the integration user runs both Apex classes, not the user who opens the report. As a result, the integration user must have access permissions for the used Apex classes.

Note

  • TPM_RTRReportingWrapper_AMS (Base Class)

    TPM_RTRReportingWrapper_AMS is a base class that contains the structures to load the input. This class contains the list of KPIs and filter criteria that you chose in the report—selected time frame or the list of customers and products. Depending on various use cases, the payload method can contain different attributes.

  • TPM_RTRSalesforceMonthlyMeasures_AMS (Base Class)

    TPM_RTRSalesforceMonthlyMeasures_AMS is the second base class that’s used for code-routing and is required to retrieve the information by a Salesforce REST endpoint (/services/apexrest/RTRSalesforceMonthlyMeasures).

  • TPM_RTRFixedFunds_AMS (The Logic Class)

    The actual logic is defined in this class. The benefit of routing to a separate third class is that the code runs only when needed.