Skip to content

Component Name: orderPricebookInput

Last Updated: 2025-09-29 Source Code: https://bitbucket.org/i2cinc/i2c.salesforce.metadata/src/STAGING/force-app/main/default/lwc/orderPricebookInput

API Name: c-orderPricebookInput Type: Form Component Target: Not specified

Business Purpose

Custom Order.Pricebook2Id field editor for Order record pages. Allows admins to change the pricebook on an order, with warnings if order items already exist. Displays current pricebook name as link, provides edit mode with pricebook lookup, validates changes.

Component Structure

Files: orderPricebookInput.html, orderPricebookInput.js (88 lines), orderPricebookInput.js-meta.xml

JavaScript Controller

Properties (API)

  • @api recordId - Order record ID

Wire Adapters

  • @wire(getRecord) - Loads Order.Pricebook2Id and Order.TotalAmount
  • @wire(getRecord) - Loads Pricebook2.Name for selected pricebook

Event Handlers

  • enableEdit() - Switches to edit mode
  • handleCancel() - Cancels edit, reverts changes
  • handlePricebookChange(event) - Updates selectedPricebookId from lookup
  • handleSave() - Saves pricebook change via updateRecord()
  • handleRefresh() - Dispatches RefreshEvent after save

Computed Properties

  • orderItemsAdded - True if TotalAmount > 0 (has products)
  • pricebookName - Loaded Pricebook name
  • pricebookUrl - Link to Pricebook record

Dependencies

  • Lightning UI Record API: getRecord, updateRecord
  • Lightning Platform: ShowToastEvent, RefreshEvent
  • Objects: Order (Pricebook2Id, TotalAmount), Pricebook2 (Name)

Usage

<!-- On Order record page -->
<c-order-pricebook-input record-id={recordId}></c-order-pricebook-input>

⚠️ Pre-Go-Live Concerns

CRITICAL

  • No validation when order has items: Changing pricebook after items added can cause price mismatches - should block or warn (line 24 checks but doesn't prevent)

HIGH

  • No unit tests: Zero coverage
  • No confirmation dialog: Pricebook change is immediate, should confirm
  • Generic error message: "Something went wrong." not helpful (line 79)

MEDIUM

  • Console.log in production: Lines 30, 39, 76
  • Clears pricebook name on null: Lines 61-62 may cause display issues

Maintenance Notes

Complexity: Low-Medium Key Notes: - CRITICAL: Component doesn't prevent changing pricebook when order has items (validation exists but not enforced) - Used on Order record pages by admins - Shows pricebook as clickable link in view mode - Edit mode uses lightning-record-picker for pricebook lookup - Should add confirmation dialog before changing pricebook with existing items - RefreshEvent refreshes entire page after save

Browser Compatibility: - Standard Lightning runtime support