- 27 Jun 2023
- 2 Minutes to read
- Print
- DarkLight
Line Items Evaluation Post Processor
- Updated on 27 Jun 2023
- 2 Minutes to read
- Print
- DarkLight
This Apex hook can alter new lines being created, remove new lines, and create new lines based on products the user selects to add.
If registered, this hook is called after the following workflow in Add Lines:
- User selects the Add Lines button on the Add Lines component.
- Optional ScopedLineItemsCreationConfigurer hook is called.
- The IQA call for the lines has been called and has updated lines.
- The LineItemsEvaluationPostProcessor hook is called.
This hook is similar to the Scoped Line Items Creation Configurer hook. However, the LineItemsEvaluationPostProcessor hook can be used when the results of the IQA call for each line is needed in the logic of the hook.
Apex hook class
- It must implement the zpl.LineItemsEvaluationPostProcessor interface.
- It must have a global access modifier.
- You must specify the Apex hook class name in the Line Items Evaluation Post Processor field of the Product Selector Configuration.
Important considerations
- The list of lines passed is the list of lines created from the product records that are selected by the user.
- For the hook to delete a line from that list, that line should not be returned in the list of lines returned by the hook. Deal Manager code will not persist any lines that are in the input to the hook but not included in the output.
- The hook can add a line by including a new line in the return response from the hook. It is up to the hook code to add the new line and to populate all fields on the line as they would have been if the user would have selected them.
- This includes fields populated by the product-to-field mapping for the selected policy type for this Product Selector Configuration.
- The Product will send all lines received back from the hook to IQA so the hook code does not have to populate the fields that would be populated by IQA registered by this Product Selector for when new lines are added.
Interface definition
**
* A base class with a single abstract method for a custom logic for post processing lines after IQ Anywhere callout finished.
* A user-facing message can be overridden by returning a non-empty value in the 'message' property.
*/
global abstract with sharing class LineItemsEvaluationPostProcessor
{
global abstract PostProcessedData postProcessLines(LineItemsData data);
// The reason of using data structures for inputs and outputs is to simplify API changes after release.
global class LineItemsData
{
@AuraEnabled global SObject[] lineItems { get; private set; }
global LineItemsData(SObject[] lineItems)
{
this.lineItems = lineItems;
}
}
global class PostProcessedData
{
@AuraEnabled global SObject[] lineItems { get; private set; }
@AuraEnabled global String message { get; private set; }
global PostProcessedData(SObject[] lineItems)
{
this.lineItems = lineItems;
}
global PostProcessedData(SObject[] lineItems, String message)
{
this(lineItems);
this.message = message;
}
}
}
Where LineItemsCreationData is the class used to return lines and the optional custom message.
Definition for the zpl.LineItemsCreationData
global class LineItemsCreationData
{
@AuraEnabled global SObject[] lineItems { get; private set; }
@AuraEnabled global String message { get; private set; }
global LineItemsCreationData(SObject[] lineItems)
{
this.lineItems = lineItems;
}
global LineItemsCreationData(SObject[] lineItems, String message)
{
this.lineItems = lineItems;
this.message = message;
}
}
Example of the class implementation
global with sharing class SimpleLineItemsPostProcessor extends zpl.LineItemsEvaluationPostProcessor
{
global override zpl.LineItemsEvaluationPostProcessor.PostProcessedData postProcessLines(zpl.LineItemsEvaluationPostProcessor.LineItemsData data)
{
SObject[] lineItems = data.lineItems;
// operate with lineItems - edit or delete
// return just created lines
//return new zpl.LineItemsEvaluationPostProcessor.PostProcessedData(lineItems);
// or return created lines and override default message
return new zpl.LineItemsEvaluationPostProcessor.PostProcessedData(lineItems, 'Custom message');
}
}