Subline Change Line Subline Updater Class
  • 04 Nov 2023
  • 1 Minute to read
  • Dark
    Light

Subline Change Line Subline Updater Class

  • Dark
    Light

Article summary

After a user updates a field on a parameter subline, this Apex hook can update fields on the parent line fields, and one or more fields on one or more sublines of that parent line.

Note

This hook is similar to the Line Change Subline Updater hook. The primary difference is that the Subline Change Line Subline Updater hook is triggered by a change to a subline.

Apex hook class

  • It must implement the SublineChangeLineSublineUpdater interface.
  • It must have a global access modifier.
  • You must specify the Apex hook class name in the Subline Change Updater Class Name field of the Product Selector Configuration.

Interface definition

global interface SublineChangeLineSublineUpdater
{
    LinesAndSublinesResponse updateLineSublinesOnSublineChange(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; }
 
    global LinesAndSublinesInputData(SObject changedSObject, String changedFieldName, SObject line, List<SObject> parameterSublines, List<SObject> tieredSublines) {
        this.changedSObject = changedSObject;
        this.line = line;
        this.changedFieldName = changedFieldName;
        this.parameterSublines = parameterSublines;
        this.tieredSublines = tieredSublines;
    }
}

As an input parameter, this method has LinesAndSublinesInputData which contains changedSObject (the object that was updated by user), a line, a changedFieldName (the field that was changed by the user on changedSObject), parameterSublines and tieredSublines.

As a return value, the method has LinesAndSublinesResponse which contains an updated line, parameterSublines and tieredSublines.

Example of the LinesAndSublinesResponse

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;
    }
}

Example of the class implementation

public with sharing class TestLineSublinesUpdaterOnSublineChange implements SublineChangeLineSublineUpdater{
    public LinesAndSublinesResponse updateLineSublinesOnSublineChange(LinesAndSublinesInputData data) {
        if ((String) data.changedSObject.get('zpl__ups_UOM__c') == 'test' && data.changedFieldName == 'zpl__ups_UOM__c') {
            data.line.put('zpl__ContractPrice__c', 100);
 
            for (SObject tieredSublines : data.tieredSublines) {
                tieredSublines.put('zpl__ups_UOM__c', 'update');
                tieredSublines.put('zpl__ups_Offer__c', 123);
                tieredSublines.put('zpl__ups_Guidance__c', 1111);
                tieredSublines.put('tbesh__Currency__c', 100);
            }
 
            for (SObject parameterSubline : data.parameterSublines) {
                parameterSubline.put('zpl__ups_Guidance__c', 1111);
            }
        }
 
        return new 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.