18 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-...
user avatar
  • 4,036
17 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 ...
user avatar
  • 28.1k
17 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={...
user avatar
14 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 ...
user avatar
  • 438k
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="...
user avatar
  • 7,585
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": { "displayValue": null, "value": "...
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 ...
user avatar
  • 10.8k
12 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> &...
user avatar
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....
user avatar
11 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 ...
user avatar
11 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 ...
user avatar
11 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 ...
user avatar
  • 438k
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 ...
user avatar
  • 560
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 ...
user avatar
9 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 ...
user avatar
  • 3,813
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 { ...
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:...
user avatar
8 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 ...
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 ...
user avatar
  • 13.4k
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 ...
user avatar
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 ...
user avatar
  • 438k
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.
user avatar
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 ...
user avatar
  • 3,605
6 votes
Accepted

Issue with passing class data from apex to javascript in LWC

The attributes in the custom class that you have created should have the AuraEnabled annotation set on them. Then those attributes will be accessible on the javascript side. public class ...
user avatar
6 votes
Accepted

Using lazy-init pattern properties on Apex data objects in LWC

When LWC actually calls some Apex, the AuraEnabled results are serialized to JSON, allowing it to be transported over HTTP (AJAX) to the client. That means the whole object (at least the AuraEnabled ...
user avatar
  • 28.1k
6 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, { ...
user avatar
6 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", "...
user avatar
  • 17.8k
6 votes
Accepted

Receiving error while iterating over a map in javascript in LWC - "e.map is not a function"

The above code has correct syntax provided boatData is an array. It looks like the Javascript object you have boatData is not an Array and hence you get an exception that .map is not a function. You ...
user avatar
6 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: ...
user avatar
5 votes
Accepted

LWC Force Refresh Wire getRecord

Today changes to cross-record summary fields, like rollups, are not detected by Lightning Data Service. We're actively working on a feature whereby Lightning Data Service (and all of its @wire ...
user avatar

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