Skip to main content
33 votes
Accepted

Order of execution of @wire in lwc

In a typical wire setup, the life cycle will be: constructor wire provisions empty object ({data, error} are each undefined) connectedCallback render renderedCallback wire provisions results from ...
sfdcfox's user avatar
  • 497k
19 votes
Accepted

How to refresh wired service getRecord manually?

To make refreshApex clear the client-side cache it is necessary to capture and store the entire result from the getRecord wire. In this case you cannot define your handler to accept an anonymous ...
Phil W's user avatar
  • 37k
19 votes

Get Object Label from API Name in LWC using wire

Salesforce should provide easy way to get the standard object labels without necessarily using ui api. With UI api one can get the label as below <template> <lightning-card title={...
Mohith Shrivastava's user avatar
19 votes

Modularize (existing) LWC for reuse and flexible distribution

This is a complex topic and I’m going to do my best to give some quick pointers but we could fill an entire white paper on this theme and I’m sure that are some things that I might overlook. Inter-...
POZ's user avatar
  • 4,419
14 votes

LWC : Events - When to use event.target.value & event.detail.value

You are talking about event reparenting. Check this question - event.getSource() alternative in LWC? (considering origin reparenting). Consider below components chain in LWC: <c:parent> &...
salesforce-sas's user avatar
13 votes

LWC Handling Multiple Dependents @Wire methods

According to LWC docs: The component’s JavaScript prefaces the value of the objectInfo parameter with $ to indicate that it’s dynamic and reactive. It references a property of the component ...
salesforce-sas's user avatar
13 votes
Accepted

Process results from two different @wire methods after the @wires are finished

Option 1: use wire handlers. Instead of writing an Attribute name, you can write a function, and store the data in attributes, then call a common function when both results are available. Example ...
sfdcfox's user avatar
  • 497k
12 votes
Accepted

Unable to pass parameters to wired property in LWC

Per the documentation here you want to mark your @wire methods differently. Also from the doc: In the wire adapter’s configuration object, prefix a value with $ to reference a property of the ...
Sebastian Kessel's user avatar
12 votes
Accepted

Record Type Selection in LWC

First thing i would do is put the combobox inside a div and only open it up once the wire data for recordtype comes from the object. <div if:true={objectInfo.data}> <lightning-combobox name="...
RedDevil's user avatar
  • 7,841
12 votes
Accepted

"Unable to read Sobject" when passing LWC getRecord data to Apex

The data you get from wire service is in the form as below: { "apiName": "Account", "childRelationships": { }, "fields": { "Name": { ...
salesforce-sas's user avatar
12 votes

When to use Slots vs Public Properties vs Getter Properties in LWC exactly?

The broad difference is that with @api attribute, is the public reactive property of the component, which can be passed through the parent. Note that this is like the backend(data) property of the ...
Rahul Gawale's user avatar
  • 12.2k
11 votes
Accepted

Where do I put isLoading=true in a @wire method?

I recommend wiring to a property and using a getter to determine if no error or data has been provisioned. @wire(getResponseMap, {...}) wiredProperty; get isLoading() { return !this....
Kevin Venkiteswaran's user avatar
11 votes
Accepted

LWC wired service getRecord won't rerender with reactive property

Documenting the resolution I found to my question here, so apparently LWC doesn't like if you you use imported references to the geo-location compound fields which is why this doesn't work with wired ...
Yogesh D's user avatar
  • 590
10 votes
Accepted

lwc dataservice architecture best practices

Firstly, a very nicely framed question! Here is what we found to be best after brain-storming: Apex methods should be used ONLY for getting the data and for DML statements. In short, it should be ...
salesforce-sas's user avatar
10 votes
Accepted

Testing LWC with multiple @wire getRecord calls with Jest

This is a known gap in the wire service test utility. It's been around for a while, but we haven't forgotten about it. There's currently some non-trivial changes being made to the internals of how the ...
TrevorBliss's user avatar
  • 3,833
9 votes
Accepted

Use LWC @wire(getRecord) when recordId is not always present

When you implement wire service, it will always be invoked the first time when its registered while component initialisation. Then it will return { data: undefined, error: undefined } However it will ...
salesforce-sas's user avatar
8 votes
Accepted

LWC : passing parameter to getrecord

In lwc wire only simple/primitive fields are reactive. This means '$recordId' is reactive but ['$urlField'] is not. Thus you have to bind optionalFields to something you can @track. import { ...
Pranay Jaiswal's user avatar
8 votes
Accepted

LWC: wire and getRecord, get field values

Provisioning data via @wire is asynchronous. In your template you need to guard against this.rec.data being undefined which is the case until data is provisioned. <template> <template if:...
Kevin Venkiteswaran's user avatar
8 votes
Accepted

Get picklist values after dynamically fetching the record type id in lwc

Below are some of the different ways to get picklist values based on recordType. To get picklist values for the default record type for the object: @wire(getObjectInfo, { objectApiName: ...
Howdy Ranger's user avatar
7 votes
Accepted

How to avoid error Cannot read property of undefined using two LWC Wired properties

To avoid this problems, it is needed to surround the code with <template if:true tag, usually it is clear and obvious when we rely on load of one parameter. However, when the code depends on two ...
Patlatus's user avatar
  • 17.3k
7 votes

How to refresh wired service getRecord manually?

Extending answer from @Phil W, For below Sample LWC Js: @api recordId = '00128000009j45tAAA'; @track wiredAccount; fields = [ACCOUNT_NAME_FIELD, ACCOUNT_DESCRIPTION_FIELD]; @wire(getRecord, { ...
salesforce-sas's user avatar
7 votes
Accepted

Does @wire provide the latest updates to a record if changed on another tab, trigger, or other process?

The wire adaptor does not have Streaming built into it. The wire adaptor uses LDS cache and this blog in a good read on how all this works under the hood. Essentially you will need a lightning Data ...
Mohith Shrivastava's user avatar
7 votes
Accepted

When using @wire I can't get lightning-datatable to show the field value

If you look at the records data, the name is deep in the records returned by the wire method. [{ "apiName": "Account", "childRelationships": {}, "id": "0012p00002NlX48AAF", "...
Raul's user avatar
  • 18.8k
7 votes
Accepted

Wiring an apex method with static parameters vs calling it in connectedCallback

A few points really do matter. If you use await, your connectedCallback can't proceed until the results come back: this.result1 = await method1(params); this.result2 = await method2(params); This is ...
sfdcfox's user avatar
  • 497k
7 votes
Accepted

Can I import the wire from lwc without having to extend LightningElement

In LWC OSS, you can freely use wire wherever you want. In Salesforce, though, you can only use wire methods inside the current LightningElement. Even if you made the service class extend ...
sfdcfox's user avatar
  • 497k
7 votes
Accepted

Fetching data in LWC via getRecord vs. Apex

The difference in structure is simply that the data is returned differently by these two services (one standard and one custom). Your custom service is probably returning simple SObject data, which is ...
Phil W's user avatar
  • 37k
6 votes
Accepted

Can I use getListUi method with Related List Views?

Currently, no. That @wire adapter does not allow relative parent (flexipage record Id). On the roadmap (no ETA) is the lightning:relatedList base component, so whenever that is released we might be ...
tsalb's user avatar
  • 3,735
6 votes
Accepted

Does LWC @wire works with custom classes?

When you declare a Apex wrapper class to be used in Aura or LWC, you have annotate each and every field with @AuraEnabled else they won't be visible in the JS or Markup of lwc or aura.
Pranay Jaiswal's user avatar
6 votes
Accepted

LWC: wire apex to property with @api param value

Define a setter-getter for tripId and use it to extract the @wire configuration value. Here's what that looks like: tripId; // value to use with @wire _trip; // private var used with getter-setter @...
Kevin Venkiteswaran's user avatar
6 votes

"Unable to read Sobject" when passing LWC getRecord data to Apex

Converting from LWC wire format to AuraEnabled format would probably look something like the following: let record = { ...Object.keys(data.fields).reduce((a,f)=>a[f]=data.fields[f].value,{}), ...
sfdcfox's user avatar
  • 497k

Only top scored, non community-wiki answers of a minimum length are eligible