/** * @description Callable implementation for calculateTotal (converted from VlocityOpenInterface). * Accepts Price and Quantity, returns TotalAmount in response envelope. * @author building-omnistudio-callable-apex */ public with sharing class MyCustomCallable implements System.Callable { public Object call(String action, Map args) { Map inputMap = (args != null && args.containsKey('inputMap')) ? (Map) args.get('inputMap') : (args != null ? args : new Map()); Map options = (args != null && args.containsKey('options')) ? (Map) args.get('options') : new Map(); if (inputMap == null) { inputMap = new Map(); } if (options == null) { options = new Map(); } switch on action { when 'calculateTotal' { return calculateTotal(inputMap, options); } when else { throw new IndustriesCallableException('Unsupported action: ' + action); } } } private Map calculateTotal(Map inputMap, Map options) { Decimal price = toDecimal(inputMap.get('Price')); Integer qty = toInteger(inputMap.get('Quantity')); if (price == null || qty == null) { return new Map{ 'success' => false, 'data' => new Map(), 'errors' => new List>{ new Map{ 'code' => 'INVALID_INPUT', 'message' => 'Price and Quantity are required and must be numeric' } } }; } Decimal total = price * qty; return new Map{ 'success' => true, 'data' => new Map{ 'TotalAmount' => total }, 'errors' => new List>() }; } private Decimal toDecimal(Object o) { if (o == null) return null; if (o instanceof Decimal) return (Decimal) o; if (o instanceof Integer) return Decimal.valueOf((Integer) o); if (o instanceof Double) return Decimal.valueOf((Double) o); if (o instanceof String) { try { return Decimal.valueOf((String) o); } catch (TypeException e) { return null; } } return null; } private Integer toInteger(Object o) { if (o == null) return null; if (o instanceof Integer) return (Integer) o; if (o instanceof Long) return ((Long) o).intValue(); if (o instanceof Decimal) return ((Decimal) o).intValue(); if (o instanceof String) { try { return Integer.valueOf((String) o); } catch (TypeException e) { return null; } } return null; } }