Skip to main content

@wire

Explore practical guides and implementation patterns for this topic.

Posts

Lightning Web Components

Mastering LWC Decorators: @api, @track, and @wire Explained

💬 In Plain Words: Three decorators, three specific jobs. @api makes a property public so the parent component can control it. @track forces a re-render when you change data inside an object or array. @wire automatically pulls data from Salesforce and refreshes whenever its inputs change. Everything else is just a plain field—and remember, plain fields in modern LWC are already reactive!
Read article
Lightning Web Components

Mastering LWC Data: @wire vs Imperative Apex & refreshApex

💬 In plain words: The @wire decorator is an automatic data subscription: it caches data, reacts to changes automatically, and serves as your default for reading information. Imperative Apex is a manual phone call: you decide exactly when to make it (like clicking a button or validating a step). Use refreshApex to update your wired data after an imperative action changes the underlying records.
Read article
Lightning Web Components

🚀 Salesforce LWC Data: Wire Caching, RefreshApex & Lazy Loading

💬 In plain words: When you use @wire in Lightning Web Components, Salesforce caches the results. If a component asks for the same data twice, it only costs one server trip. That gives you free speed, but it creates a risk of stale data. When you change data, you must manually call refreshApex to force a fresh copy. Lazy loading means you don't fetch or render heavy components until the user actually scrolls down to see them. 📌 Example: Handling Stale Cache Data Screen A uses @wire to fetch getOpenCases . A user opens Screen B, edits a case, and returns to Screen A. The list on Screen A is now stale, because it is being served from the local wire cache rather than the server. To fix this, store the entire wired result object ( wiredCases ) and call refreshApex(this.wiredCases) immediately after the edit in Screen B completes. The cache gives you speed; the refresh gives you the truth.
Read article