- 28 Jun 2023
- 2 Minutes to read
- Print
- DarkLight
Line Change Subline Updater Class
- Updated on 28 Jun 2023
- 2 Minutes to read
- Print
- DarkLight
When a user updates a field on a parent line, this Apex hook can update additional parent line fields and one or more fields on one or more sublines of that parent line.
The hook occurs within the following workflow:
- In the Edit Lines modal, the user selects a parent line and updates the editable field.
- Before the user selects Save, the parent line, all sublines created for that parent line, and the field that was changed are sent to the Apex hook.
- Some custom logic or calculations, an IQA call, or both are made (IQA called by hook).
- The parent line value and subline values returned by the hook service are displayed in the Edit Lines modal.
- If the user selects Save, the fields changed by the user and the hook are saved.
- If the user selects Cancel, the changes are not saved.
- The user can continue changing editable fields on a line or subline.
Apex hook class
- It must implement the LineChangeSublineUpdater interface.
- It must have a global access modifier.
- You must specify the Apex hook class name in the Line Change Subline Updater Class Name field of the Product Selector Configuration that is mapped to the Line Items component to be affected by the hook.
Interface definition
global interface LineChangeSublineUpdater
{
LinesAndSublinesResponse updateSublinesOnLineItemChange(LinesAndSublinesInputData data);
}
As an input parameter, this method has LinesAndSublinesInputData which contains changedSObject (the object that is updated by the user), line, changedFieldName (the field that was changed by user on changedSObject), parameterSublines and tieredSublines.
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 a return value, the method has LinesAndSublinesResponse which contains an updated line, parameterSublines and tieredSublines.
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
global class TestSublineFieldUpdater implements LineChangeSublineUpdater {
public LinesAndSublinesResponse updateSublinesOnLineItemChange(LinesAndSublinesInputData data) {
if (data.line.get('zpl__ContractPrice__c') == 1 && data.changedFieldName == 'zpl__ContractPrice__c') {
data.line.put('zpl__ContractPrice__c', 10);
for (SObject parameterSubline : data.parameterSublines) {
parameterSubline.put('zpl__ups_Guidance__c', 3);
parameterSubline.put('zpl__ups_Offer__c', 2);
parameterSubline.put('zpl__ups_UOM__c', 'updated');
}
for (SObject tierdSubline : data.tieredSublines) {
tierdSubline.put('zpl__Value__c', 10);
tierdSubline.put('zpl__ups_Guidance__c', 3);
tierdSubline.put('zpl__ups_UOM__c', 'updated');
tierdSubline.put('zpl__ups_Offer__c', 100);
}
}
return new LinesAndSublinesResponse(data.line, data.parameterSublines, data.tieredSublines);
}
}