🧪 Experimental KB — Official knowledge hub: community.kaptio.com

How to Trigger Itinerary Recalculation Programmatically via Apex

Customer needed to trigger itinerary price recalculation from custom Apex code and wanted to know how to detect when the recalculation completes.

apex recalculation itinerary async-request pricelinefactory integration

Problem

Customer needed to trigger itinerary price recalculation from custom Apex code and wanted to know how to detect when the recalculation completes.

What We Found

Kaptio provides two methods for programmatic recalculation: (1) PriceLineFactory global class for recalculating individual itinerary items, and (2) AsyncRequest records for recalculating entire itineraries. There is no Platform Event emitted on completion, but the RecalculationStatus field can be monitored.

Solution

  1. For ITINERARY ITEMS only: Use the PriceLineFactory global class. Documentation and code samples available at https://docs.kaptioapis.com/kaptio-code-sample/-/price-line-factory. Note: No completion notification mechanism available with this method.
  2. For FULL ITINERARY recalculation: Create a KaptioTravel__AsyncRequest__c record with these values: (1) KaptioTravel__AsyncType__c = ā€˜Recalculate All’, (2) KaptioTravel__Params__c = serialized itinerary JSON, (3) KaptioTravel__Error__c = false
  3. Query the itinerary with ALL required fields (see code sample below) and serialize it into the Params field as JSON with key ā€˜itinerary’
  4. To detect completion: Monitor the KaptioTravel__RecalculationStatus__c field on the itinerary. It will be set to ā€˜Recalculation Completed’ on success or ā€˜Errors’ on failure

Notes

  • Each AsyncRequest record can only process ONE itinerary. If multiple itineraries need recalculation, create separate AsyncRequest records for each.
  • The itinerary query must include many related Channel and Brand fields for the recalculation to work correctly. See the required SOQL query in the code sample.
  • Required itinerary fields include: Id, Account, BusinessUnitId, BrandCurrencyIsoCode, BuyConversionRatesJSON, Channel, CommissionTaxProfile, CorporateCurrencyIsoCode, Currency, CurrencyFactor, CurrencyFactorBCY, LockSellPriceMode, OpenAmendment, RecalculationStatus, RecalculationErrors, SellRatesQuoteDateConvert, UseLightningVersion, plus many Channel and Brand relationship fields

Warnings

āš ļø PriceLineFactory can only recalculate itinerary items, NOT entire itineraries āš ļø Kaptio does NOT emit a Platform Event on recalculation completion - you must poll the RecalculationStatus field or use Flow/Apex/CDC to react to field changes


Source: KHELP-12299

Was this article helpful?