HomeGuidesDeveloper HubRelease Notes
Get supportBook a chat
Developer Hub
These docs are for v2.114. Click to read the latest docs for v2.208.

Key Creation for Payout

As a way of organizing your payout records better and to help you spare some time in any analyses you might do, the system will group payout records whenever possible. By default, this process uses information from the Member and the Payout Date to generate a key that will bring several Payout Items together to be approved or rejected as a whole by the admin.

Let's say that you have 2 promotion that will create a payout for the member every time that they close an opportunity, and they have the same Payout Date setup, than each time that Abigail Wells (a program member) closes a opportunity, a new payout item will be added to her payout record. This payout record will be later approved by the admin, paying to Abigail the sum of all the payouts she received at once.

However, you may not want the payout items to be grouped by those criteria. Maybe you prefer to pay the member based on other parameters linked to their actions.

With the Key Creation for Payout, you can create your own way of generating a key to group the Member's actions, complying to your business preferred criteria. For example, you may need to group not only by Member and Payout Date, but also by a specific Promotion or Challenge. Follow the steps below to create the customization:

Creating Custom Fields

Create a custom field with a formula to grab information you would like to use as part of the key.

Go to Setup and click the Object Manager tab. Look for Point and on the Fields and Relationships section, create a new Formula type field.

🚧

Promotion and Challenge are existing fields in the package, so if you want to use them, it's not needed to create new fields.

Now, create a field to be filled when a payout is created based on your key.

Back to the Object Manager, look for Payout. On the Fields and Relationships section, create a new . field.

Create Apex Class

In your Org, go to Setup and search for Apex Classes in the Quick Find box. Click on New to add your class. Give it any name you'd like.

public class CustomPayoutReflection implements PayoutInterface {
    /**
     * Method to define the "key" based on a point record 
     * (Member Id and Currency Id already included by default)
     * 
     * You can use any Point formula fields,
     * they are calculated before calling this method
     */
    public string getExternalId(Point__c point) {;
        return point.Payout__r.PayoutDate__c.format('yyyy-MM-dd') + point.KeyFormulaField__c;
    }

    /**
     * Method to set the payout additional fields when created
     * 
     * You can use any custom formula field,
     * they are calculated before calling this method
     */
    public void setFields(Payout__c payout, Point__c point) {
        
        payout.Field_1__c = point.FormulaField_1__c;
        payout.Field_2__c = point.FormulaField_2__c;
        /* ... */
        payout.Field_N__c = point.FormulaField_N__c;
    }
}

Once the class has been created, you’ll need to add it as a value to the Custom Setting.

Adding value to the custom setting

In Setup, quick find Custom Settings. Locate the setting called Public Settings (FieloPLT__PublicSettings__c) and click on Manage to its left.

Next, click on Edit in order to add the name of the recently created class as a value in the Payout Reflection Class (PayoutReflectionClass__c) field.