Tiered Subline Change Line Subline Updater Class
  • 28 Jun 2023
  • 3 Minutes to read
  • Dark
    Light

Tiered Subline Change Line Subline Updater Class

  • Dark
    Light

Article summary

When a tiered pricing line is updated, added, or removed, this Apex hook can update that tiered pricing subline, other tiered pricing sublines on that parent line, parameter sublines on the same parent line, or the parent line.

The hook occurs when a user changes a field on a tiered pricing subline in the Edit Lines modal.

Apex hook class

  • It must implement the zpl.TieredSublineChangeLineSublineUpdater interface.
  • It must have a global access modifier.
  • You must specify the Apex hook class name in the Tiered Subline Change Updater Class Name field of the Product Selector Configuration that is mapped to the Edit Lines Modal component to be affected by the hook.

Interface definition

global interface TieredSublineChangeLineSublineUpdater
{
    LinesAndSublinesResponse updateLineSublinesOnTieredSublineChange(LinesAndSublinesInputData data);
}


global class LinesAndSublinesInputData {
    @AuraEnabled global SObject changedSObject { get; private set; }
    @AuraEnabled global SObject line { get; private set; }
    @AuraEnabled global String changedFieldName { get; private set; }
    @AuraEnabled global List<SObject> parameterSublines { get; private set; }
    @AuraEnabled global List<SObject> tieredSublines { get; private set; }
    @AuraEnabled global Boolean isTieredSublineAdded { get; private set; }
    @AuraEnabled global Boolean isTieredSublineDeleted { get; private set; }
    @AuraEnabled global Boolean isTieredSublinesAllDeleted { get; private set; }

    global LinesAndSublinesInputData(SObject changedSObject, String changedFieldName, SObject line, 
                                        List<SObject> parameterSublines, List<SObject> tieredSublines,
                                        Boolean isTieredSublineAdded, Boolean isTieredSublineDeleted, 
                                        Boolean isTieredSublinesAllDeleted) {
        this.changedSObject = changedSObject;
        this.line = line;
        this.changedFieldName = changedFieldName;
        this.parameterSublines = parameterSublines;
        this.tieredSublines = tieredSublines;
        this.isTieredSublineAdded = isTieredSublineAdded;
        this.isTieredSublineDeleted = isTieredSublineDeleted;
        this.isTieredSublinesAllDeleted = isTieredSublinesAllDeleted;
    }
}
Note

The user can use the following new properties in the code:

  • isTieredSublineAdded—Triggers the action when a user adds tiered pricing subline.
  • isTieredSublineDeleted—Triggers the action when a user deletes tiered pricing subline.
  • isTieredSublinesAllDeleted—Triggers the action when a user deletes all sublines using the Delete All button. This property can be used to update only parameter sublines and line fields, because tiered pricing sublines are all deleted and they do not exist.

Example: LinesAndSublinesResponse response

global class LinesAndSublinesResponse {
    @AuraEnabled global SObject line;
    @AuraEnabled global List<SObject> parameterSublines;
    @AuraEnabled global List<SObject> tieredSublines;

    global LinesAndSublinesResponse(SObject line, List<SObject> parameterSublines, List<SObject> tieredSublines)
    {
        this.line = line;
        this.parameterSublines = parameterSublines;
        this.tieredSublines = tieredSublines;
    }
}

Example1 of the class implementation

global with sharing class TestUpdaterOnTieredSublineChange implements TieredSublineChangeLineSublineUpdater{
    global LinesAndSublinesResponse updateLineSublinesOnTieredSublineChange(LinesAndSublinesInputData data) {
        if (data.isTieredSublineAdded) {
            //do some actions
        }
        else if (data.isTieredSublineDeleted) {
            //do some actions
        }
        else if (data.isTieredSublinesAllDeleted) {
            //do some actions
        }
        else if ((Double) data.changedSObject.get('mchmut__Test_number__c') == 111 && data.changedFieldName == 'mchmut__Test_number__c') {
           //do some actions
        }
        else if (data.changedFieldName == 'mchmut__Tiered_Picklist__c') {
            //do some actions
        }

        return new LinesAndSublinesResponse(data.line, data.parameterSublines, data.tieredSublines);
    }
}

Example2 of the class implementation

global with sharing class q4tp_TPLineChange implements zpl.TieredSublineChangeLineSublineUpdater{
global zpl.LinesAndSublinesResponse updateLineSublinesOnTieredSublineChange(zpl.LinesAndSublinesInputData data) {
 
        if (data.isTieredSublineAdded) {
            //do some actions
        }
        else if (data.isTieredSublineDeleted) {
            //do some actions
        }
        else if (data.isTieredSublinesAllDeleted) {
            //do some actions
        }
        else if ((Double) 16 == 111 && data.changedFieldName == 'box') {
           //do some actions
        }
        else if (data.changedFieldName == 'zpl__UpperBound__c') {
            //update Expected Rebate on the changed subline line
            //updated Expected Rebate on the parent line
            Decimal RemainingTotExpQty = (Decimal) data.line.get('TSO_TTM_Volume__c');
            // This code assumes that Net Price is the policy type, so the value field is the price
            Decimal CurrentPrice = (Decimal) data.line.get('zpl__PolicyValue__c');
            Integer NumbOfTieredSublines = data.tieredSublines.size();
            Integer i = 0;
            Decimal CurrentLowBound = 0;
            while (i < NumbOfTieredSublines){
                for (SObject tieredSubline : data.tieredSublines) {
                            // take care of null upper bound
                            Decimal RecordUpperBound;
                            if (tieredSubline.get('zpl__UpperBound__c') == null){
                                RecordUpperBound = 999999999;
                            }
                            else{
                                RecordUpperBound = (Decimal) tieredSubline.get('zpl__UpperBound__c');
                            }                       
                    if ((Decimal)tieredSubline.get('zpl__LowerBound__c')==CurrentLowBound){
                        if (RemainingTotExpQty > 0){                                                     
                            
                            if(RecordUpperBound-(Decimal)tieredSubline.get('zpl__LowerBound__c') > RemainingTotExpQty){
                                tieredSubline.put('q4tp_ExpQty__c', RemainingTotExpQty);
                                RemainingTotExpQty = 0;
                                CurrentLowBound = RecordUpperBound;
                            }
                            else{
                                tieredSubline.put('q4tp_ExpQty__c', RecordUpperBound-(Decimal)tieredSubline.get('zpl__LowerBound__c'));
                                RemainingTotExpQty = RemainingTotExpQty-RecordUpperBound;
                                CurrentLowBound = RecordUpperBound;
                            }
                        } // end if (RemainingTotExpQty > 0){
                        else{
                            tieredSubline.put('q4tp_ExpQty__c', 0);
                            RemainingTotExpQty = 0;
                            CurrentLowBound = RecordUpperBound;
                        }
                    }
                    tieredSubline.put('q4tp_ExpRebate__c', ((Decimal) tieredSubline.get('q4tp_ExpQty__c')*CurrentPrice * ((Decimal) tieredSubline.get('zpl__Value__c')/100)));

                } // end for loop
                i++;
            } // end while loop
            
            // rollup total rebate for parent line
            Decimal TotalRebate = 0;
            for (SObject tieredSubline : data.tieredSublines) {
                TotalRebate = TotalRebate + (Decimal)tieredSubline.get('q4tp_ExpRebate__c');
            }
            data.line.put('q4tp_ExpTotRebate__c',TotalRebate);
        }

        return new zpl.LinesAndSublinesResponse(data.line, data.parameterSublines, data.tieredSublines);
    }
}


Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.