Must-readLWC and UI
Moving display logic from Apex into HXL widget formulas (opens in a new tab)
You will learn how to express conditional display, badge coloring, arithmetic and blank checks as formulas inside HXL widget JSON, what the formula functions can and cannot do, and why deployed widget schemas can only grow.
Before: Apex
- Precomputes ratingVariant
- Computes winRate in Apex
- Sends hasPhone and hasOpenPipeline
After: widget formulas
- CASE() picks the badge variant
- IF() guards the win rate division
- NOT(ISBLANK()) checks the phone
HXL widgets are declarative JSON components, currently in beta, that can be embedded in Claude, ChatGPT and Agentforce. Their {!…} expressions can use math, comparison and logic operators and functions such as IF, CASE, AND and LEN, so display logic can sit beside the display rather than in Apex. The author shows an account card whose display fields were first precomputed in an Apex DTO and then replaced with formulas for visibility, badge variant, win rate and phone presence.
The author notes limits. There are no formatting functions for dates or currency, so those values still need formatting in Apex, and there is no aggregate such as SUM or AVERAGE across a list. Moving an existing widget also has a catch: a deployed schema.json can only grow, so removing old properties requires deploying a new widget bundle and repointing the Custom Lightning Type renderer.
The post also points to the Headless Experience Layer Playground for testing formulas live and to a formula reference in the Salesforce platform-widget-generate skill for coding agents.
Read the original at Salesforce Developers Blog (opens in a new tab)