New answers tagged

0 votes

LWC seems to be interfering with history stack when using window.history.pushState()

Given the parameter names, it appears you're in Salesforce. Assuming that, you should be using NavigationMixin: import { CurrentPageReference, NavigationMixin } from 'lightning/navigation'; import { ...
  • 462k
1 vote
Accepted

javascript filter child object fields

This is more of a specific JS question.Since we just need to check if any one array element satisfies the condition, we can use JS some function for checking the nested array as below : const ...
  • 1,069
1 vote
Accepted

How to get logged in User's PermissionSetGroup id in LWC?

The error you're getting is: The related lists UI API currently does not support this related list Unfortunately, not all objects are supported by the UI API, and this appears to be a limitation. ...
  • 462k
1 vote

How do I check if LWC component has a public method

Below approach using JS typeof operator will determine if setCustomValidity exists on the DOM element. const inputArray = this.template.querySelectorAll(".inp-cls"); inputArray.forEach(inp =...
  • 1,069
0 votes

Unable to install lwc-dev-server / run sfdx force:lightning:lwc:start

From your description and logs, it seems like a compatibility issue between sfdx plugin and oclif version. Update the @oclif/core module to the latest version by running the command npm install @oclif/...
  • 115
0 votes

Lightning tab with LWC name stuck in "Loading"

I am not sure as you have not posted the code here. Please post sample code to understand your question better. Here is a sample to create a tab in LWC. I don't see any issue loading name HTML <...
1 vote
Accepted

Cloning the task list view datatable in custom LWC (Status value and clickable button in same column)

You can use an htm table and an apex helper class...try the code below Apex: public with sharing class GetTaskController { @AuraEnabled(cacheable=true) public static List<TaskWrapper> getTasks()...
5 votes
Accepted

LWC: Getting original element that dispatched event that bubbles

This is the expected behavior, as specified in the documentation. When an event bubbles up the DOM, if it crosses the shadow boundary, the value of Event.target changes to match the scope of the ...
  • 462k
3 votes
Accepted

How to redirect to start of the flow using LWC embedded in the same flow

There is no such thing as a FlowNavigationStartEvent, but you can engineer your component and flow to cooperate to achieve what you want. I would address this by: Having an output only property for ...
  • 31.4k
0 votes

Declaratively mocking a custom LWC in a single unit test

Answer replicated from: How do I mock a child LWC in a parent's Jest Unit Test? Let's say we have two components parentComponent and childComponent. parentComponent includes childComponent in its ...
0 votes
Accepted

Customizing a Flow's Finish Behavior

Found out it's flow-finish-behavior attribute on the flow not flowFinishBehavior as stated on the top.
1 vote
Accepted

How do I mock a child LWC in a parent's Jest Unit Test?

In order to mock childComponent only in the test for parentComponent we need to: Build a skeleton stub for childComponent as a JS file. Instruct the parentComponent test to use this file instead of ...
0 votes

How to preserve formatting in long text fields in LWC components

just use lightning-formatted-text instead of lightning-formatted-rich-text
0 votes

Dynamically provide values to getRecords wire adapter

Ok, so after 30 mins of trying a few more things I got there, I had seen another question where someone suggested moving the records array of objects out on it's own and then you can refer to it ...
1 vote
Accepted

JavaScript strict mode is causing my promise to be rejected and throw an error

if (reject) { reject(reject); } else { resolve(resolve); } You're breaking the rules of how Promises work. While I haven't managed to exactly replicate your error, I can tell you the problem is ...
  • 462k
2 votes
Accepted

Usage LWC in flow returns error when package creation

The component reference in your flow is currently: <extensionName>c:navigateButton</extensionName> This needs to be updated to use the namespace prefix for your package. If your package ...
  • 31.4k
1 vote
Accepted

Problem with replacing if:true with lwc:if

My HTML page contained 11 if:true tags and 1 if:false. After replacing all of these one by one, I found out that the problem was with the if:false. What I had: <template if:false={...
3 votes

Alternate to if:false in LWC

As far as I'm aware, you are meant to use either of the two solutions. I would personally recommend flipping the Boolean value, as that is a trivial code change. This is actually similar to most other ...
  • 462k
0 votes

What is the best approach for callouts to external system?

Both approaches are valid for getting external system data to the front end using LWC, but the choice depends on your specific requirements and constraints. If you are trying to get data from a REST ...
0 votes

What is the best approach for callouts to external system?

I would use fetch unless: CORS doesn't allow it You need the data for backend-only operations, i.e. fetch data and immediately update some fields.
  • 250
0 votes
Accepted

Dynamic radio buttons not working correctly within html for:each loop in lwc component

For a radiogroup to work properly, it needs a unique name. Assuming your questions are unique, use these as the name. Eg: <lightning-radio-group name={ques.question} options={ques.options} ...
2 votes
Accepted

Better LWC performance: sibling components with separate wires, or a single service component with a wire that sends data via Message Channel

Multiple requests with the exact same parameters will coalesce into a single network call, or none, if the cache is warm. If any of the parameters are different, these are not considered identical ...
  • 462k
0 votes

Error ssl reason: write EPROTO and wrong version number

Check your sfdx version. This is a known issue w/ version 55.4.0 and above. https://github.com/forcedotcom/salesforcedx-vscode/issues/4261
0 votes

Hello, can anyone tell how can we preselect values in lightning dual listbox LWC?

I don't see the code where you are setting the defaultValues, either way you can follow the below approach works for me - options =[{label: 'Prescription Drive', key: 'Prescription Drive', value: '...
0 votes

How to import Excel files from static resources using Loadscript in LWC?

First of all, to load the entire file, you just use the resourceUrl without anything beyond the path. Secondly, you can only load JavaScript files with loadScript. If you want to use the file for ...
  • 462k
1 vote
Accepted

lightning-datatable column builder class

In JavaScript, we typically define functions with zero or one main parameters, and any number of optional parameters defined as an Object. This allows us to have great flexibility in writing methods ...
  • 462k
1 vote
Accepted

Conditional Criteria on Lightning button disabled attribute doesn't work

For disabling a particular button from the list of objects , you need to add a boolean property to each object of the iteration array. e.g. Let's consider actualHoursItems as below : actualHoursItems =...
  • 1,069
0 votes
Accepted

Lightning-accordion not collapse

The issue here is not due to accordion inside table column. If a accordion has only one section then it will always remain open for accordion without allow-multiple-sections-open attribute. There are ...
  • 1,069
0 votes

How to fetch other fields (e.g. name) from Lookup Field on LWC from Array Object returned by Apex

In your Html Template you are referring to two fields Client__r.Name Clients_Accommodation__r.Name First In your Apex controller, when you are looping on clientsAccommodations you need to add like ...
7 votes
Accepted

For SOQL queries, can "WITH USER_MODE" safely replace "WITH SECURITY_ENFORCED"?

We are recommending developers to use WITH USER_MODE and avoid using the WITH SECURITY_ENFORCED In fact at some time in the future it's likely we may retire WITH SECURITY_ENFORCED The WITH USER_MODE ...
0 votes

Can we use NPM packages in my LWC Custom Component?

This stuff isn't well documented, but I was able to incorporate the expr-eval library by taking the following steps: Retrieve the bundled code from cdnjs (https://cdnjs.com/libraries/expr-eval/2.0.2) ...
1 vote
Accepted

LWC not displaying any Data in component when attempting to display the Account on Contact

Please try the below code.I hope it would work Please Update your markUp with the below code <template> <lightning-card title="Account Information" icon-name="standard:...
0 votes

How to embed Qualtrics script in Salesforce LWC?

No. Inline scripts can't run in LWC or Aura. Random websites can't be opened by script (CSP violations). Creating dynamic script elements are not allowed. The onload event will have already fired by ...
  • 462k
0 votes

Need string[] or custom object in lightning__RecordPage targetConfig property

You can add a String property like - <property label="ToBeFilled" name="name" type="String" default=""/> You can add string values separated by commas. ...
0 votes

how to move focus to lightning input field?

We can handle this by either having same data-id for the elements(tag and lightning-input) in this case or a particular format to relate them. Both the approaches are described below : 1. Same data-id ...
  • 1,069
1 vote
Accepted

How to deserialize JSON array which contains custom fields? Passing data from LWC to APEX

You're going to have to choose one: (a) rename Amount_Kg to be a proper custom field, and then use the custom object directly, or (b) rename the properties in your wrapper class to not use __ in the ...
  • 462k
0 votes

Conditional Criteria on Lightning button disabled attribute doesn't work

In LWC you can not add conditions like this, you need to create a JS variable and do the calculation over there. get isDisabled(){ return this.index === 0 || this.actualHoursItems.length != this....
0 votes

How to convert string with comma-separated values to lwc picklist

<template> <lightning-card> <lightning-combobox name="progress" label="Status" value={value} placeholder="Select ...
2 votes
Accepted

How can you use getSObjectValue() in a child component who's property is declared with @api?

As I've said a few times before, Proxy is almost certainly not the problem here. Proxy is nearly perfectly transparent to code running live, it just so happens that console.log outputs the Proxy ...
  • 462k
0 votes
Accepted

Not able to see the values of object?

Given you already have the data available within your component, I would avoid trying to get this data using a query selector and use it directly. To construct the cart you should be able to do the ...
0 votes

How to add css to change the label color of navigation icon in LWC

There are no styling hooks for label's color, so you cannot change it. Even if you set valid css rules in your component, it will not leak into standard lightning-vertical-navigation-item-icon ...
  • 5,594
0 votes

Securely call an external API from a LWC

You should never directly call other authenticated systems from the browser. That should always be done via Apex. LWC -> Apex -> other system -> Apex -> LWC For authentication/...
  • 144
-1 votes
Accepted

LWC- when I click with in the div relevant checkbox should be checked

handleDivClick(event) { const checkbox = event.currentTarget.querySelector('lightning-input'); checkbox.checked = !checkbox.checked; const changeEvent = new CustomEvent('change'); ...
2 votes
Accepted

this.template.querySelector is not returning list of objects in LWC

Proxy is a tool used by developers to trap certain events. Lightning Locker Service and Lightning Web Security uses a Proxy to ensure that data is accessed correctly. As a simple demonstration to this,...
  • 462k
1 vote

Dynamic question display in salesforce

I think this post might help you. https://developer.salesforce.com/docs/component-library/bundle/lightning-tree/example
0 votes
Accepted

LWC Component Error: Cannot read properties of undefined (reading 'description)

If you look at the documentation, you'll see that description is not a valid attribute for lightning-combobox. The description attribute is a property you can add to an individual element in the list ...
  • 462k
1 vote

LWC- when I click with in the div relevant checkbox should be checked

Why you are not trying to update the checkbox value using - checkbox.checked = true; instead of firing the dispatch event. I think you want to change the checkbox value on clicking the div element, in ...
-1 votes

MetadataService API custom field label update

You have not shared the JS. I am sharing the apex code to update the multiple fields using MetadataApi. MetadataService.MetadataPort service = MetadataServiceExamples.createService(); ...
0 votes

How to remove column adjuster in Lightning Data Table?

In your columns attribute, set the property for fixedWidth to the desired value in pixels. These columns will not be resizable, and the right-hand grip will disappear (do this for all columns to fix ...
  • 462k
1 vote
Accepted

How to make DIV sticky so that its position does not change on scrolling the page in LWC

The root cause of centre div not sticking is that the sticky position is applied to incorrect div. First , you need to remove all slds-scrollable, slds-scrollable_y css classes from the markup. Second ...
  • 1,069

Top 50 recent answers are included