Pre- and Post-Processing Logic for CPQ APIs

Each of the CPQ APIs provide an option to write custom pre- and post-processing logic (hooks) to implement custom logic. Pre-hook logic is executed before the API is executed, while post-hook logic executes after the API executes.

Follow these steps to implement pre- and post-hook logic for CPQ APIs:

  1. Write the custom class to implement the pre and post hook.

    Below is a sample.

    1global with sharing class CPQCustomHookImplementation implements vlocity_cmt.VlocityOpenInterface{
    2
    3global Boolean invokeMethod(String methodName, Map<String, Object> input, Map<String, Object> output, Map<String, Object> options) {
    4    if( methodName.equalsIgnoreCase('getCartsItems.PreInvoke')) {
    5         getCartsItems_PreInvoke(methodName, input, output,options);
    6         return true;
    7    }
    8    if( methodName.equalsIgnoreCase('getCartsItems.PostInvoke')) {
    9         getCartsItems_PostInvoke(methodName, input, output,options);
    10         return true;
    11    }
    12    return false;
    13 }
    14
    15 private void getCartsItems_PreInvoke(String methodName, Map<String, Object> input, Map<String, Object> output, Map<String, Object> options) {
    16   //This method gets called before getCartsItems
    17 }
    18
    19private void getCartsItems_PostInvoke(String methodName, Map<String, Object> input, Map<String, Object> output, Map<String, Object> options) {
    20   //This method gets called after getCartsItems
    21}
  2. Create the Interface Implementation.

    1Interface Name = CpqAppHandlerHookInterface, Implementation = CPQCustomHookImplementation

    When invoking a CPQ API using a VIP, you must also create a custom setting with the same data as the interface implementation. The custom setting name should be the name of the interface implementation and the class should be the class name used in interface implementation.

    For information about creating an interface implementation, see:

    Interface Packages, Types, and Default Implementations

    Working with Implementations

    Add a New Interface Implementation

    For information about custom settings, see Vlocity Triggers.

  3. Make the interface implementation active. For information, see Working with Implementations.