Skip to main content
20 votes
Accepted

Array.push() won't update Lightning Web Component View

If you rebuild the array as below and reassign, the @track sees the change: this.myArray = [...this.myArray, myNewElement]; My guess is that the @track isn't noticing the original push() in the ...
DaveS's user avatar
  • 1,614
18 votes
Accepted

Apex Array Slice

Here's a pattern that seems relatively efficient and easier to understand. public static List<Object> slice(List<Object> input, Integer ge, Integer l) { List<Object> output = ...
Adrian Larson's user avatar
  • 151k
11 votes
Accepted

Pre-defined Length List of Lists

The syntax changes slightly when you use the parameterized syntax: List<List<String>> colorLists = new List<List<String>>(1); If you want the list to be empty, do not provide ...
sfdcfox's user avatar
  • 497k
11 votes

Apex Array Slice

While it's not a bad start, I can think of a number of problems: No bounds checks are provided Only Id and SObject are supported SObject version returns generic list, does not support upsert Has ...
sfdcfox's user avatar
  • 497k
11 votes

Array.push() on a @tracked array doesn't cause component refresh in lightning-accordion in LWC

If we create a new array as below, @track sees the change: this.myArray = [...this.myArray, myNewElement]; My guess is that the @track isn't noticing the original push in the array since an array is ...
DaveS's user avatar
  • 1,614
8 votes

Apex Array Slice

There's already some good answers here, but I figured I'd throw my hat into the ring anyways. In my approach, I've tried to stay as close to the Javascript versions as possible. The JS slice is a ...
martin's user avatar
  • 12.7k
6 votes
Accepted

3 nested aura:iteration's don't work properly

Yes, you can nest iterators "infinitely" (up to some really large maximum); it looks like you had an unused value provider name prod in your code. Here's a revised, Short, Self Contained, Correct (...
sfdcfox's user avatar
  • 497k
6 votes
Accepted

Error: Invalid mutation: Cannot set [value] on [array]. [array] is read-only

An attribute marked @api can't be modified by the component once set (it may only be set once during the component's construction). You need to copy the array first. Here's the change you need to make:...
sfdcfox's user avatar
  • 497k
5 votes
Accepted

LWC JavaScript: Can't Add a Property to Objects While Looping through an Array of Those Objects

Presuming that this came from a server call, you need to copy the objects entirely: let tempFieldWrapperArray = this.fieldSetWrapper.fieldWrappers.map(element => ({...element})); Or: let ...
sfdcfox's user avatar
  • 497k
4 votes

How does Guide Template Language parse a straight JSON array?

Short answer is that it should, but it doesn't. I am going off assumptions as I have no definitive proof, but even attempting to use the example in the official docs does not work. <ul class="...
Gortonington's user avatar
  • 30.7k
4 votes

How To Split String by space and store each character or substring in array

Usage of String.split method doesn't fit your requirements, as you will have '(1' first element and '2)' third element. Use String.splitByCharacterType method. Splits the current String by ...
Oleksandr Berehovskyi's user avatar
4 votes
Accepted

How to pass a mutable Array from Parent Component to Child Component in LWC

If this approach of JSON.parse + JSON.stringify might break with future releases of LWC (is it stable enough ?) Yes, it's perfectly normal JS, although not the most efficient. However, a point to ...
sfdcfox's user avatar
  • 497k
4 votes
Accepted

Lightning Web Component Error: ['set' on proxy: trap returned falsish for property '0']

The property set by the parent component is immutable, which mean's you can't modify that. You need to use the getter setter for the public property. _cartItems; ... @api get cartItems(){ return ...
Rahul Gawale's user avatar
  • 12.2k
4 votes
Accepted

Unable to pass an array from parent LWC to child LWC setter method

An inner mutation like calling push() on an array doesn't trigger the framework to rerender or fire setters. The framework is observing changes to the scopeValues property in the parent, but not to ...
David Reed's user avatar
  • 93.2k
4 votes
Accepted

Convert string to list of String in Apex

That's how the split() method works. You give it a delimiter, and it creates a new item in the resulting list after every instance of the delimiter that it encounters. The delimiter is supposed to be ...
Derek F's user avatar
  • 62.7k
4 votes
Accepted

Convert Int Array to Blob

Apex doesn't have the notion of "byte arrays", unfortunately, so there's no one-liner that can do this. The best you can do if you start from this array would be something like: Integer[] ...
sfdcfox's user avatar
  • 497k
4 votes
Accepted

Convert PDF file returned as byte[] in apex callout into blob and Save as file

You don't need to do anything special, just get the body's Blob content: Blob fileContent = res.getBodyAsBlob(); ContentVersion cv = new ContentVersion(VersionData=fileContent); // Don't forget the ...
sfdcfox's user avatar
  • 497k
4 votes
Accepted

Reactive array of objects and "Use Lightning Web Security for Lightning Web Components"

Primitives are reactive, objects are not. However, you can just add @track to make an object reactive: import { LightningElement, track } from 'lwc'; export default class Widgets extends ...
sfdcfox's user avatar
  • 497k
3 votes
Accepted

Order of rendered list items differs from items order in Javascript

This is a bug as reported in salesforce issue: Workaround: Set an empty array before setting the actual array of items. Note: This workaround will rerender the whole array. Code: cmp.set("v....
RedDevil's user avatar
  • 7,841
3 votes
Accepted

Convert String array to Set of string in apex class

From what I could tell is you want to end up with a unique list of Franchise__c strings from the queried records, if so.... You code could be reduced to this: Set<String> SplitList = New Set&...
Eric's user avatar
  • 54.2k
3 votes
Accepted

Alternative for many if/then AMPscript statements?

You can load the city codes in a Data Extension and do a lookup. %%[ var @cityCode, @city set @cityCode = AttributeValue("cityCode") set @city = Lookup("cities", "city", "cityCode", @cityCode) ]%% &...
Adam Spriggs's user avatar
  • 30.8k
3 votes

Get all automations that exist using SOAP using C#

I have coded it with the same result, but I have found some interesting thing, you can call Retrieve method filtering by "isActive" parameter and "true" value, and after repeat the call filtering by "...
Jacob's user avatar
  • 31
3 votes
Accepted

how to get value from map when wrapper class is the key

I think that this error is misleading. At least I'm getting nothing from it. My first suspicion what is wrong: You're trying to use your custom created class as a map key but you don't have equals ...
user1974566's user avatar
  • 2,325
3 votes
Accepted

Array with saving previous objects in Lightning

You need to start from your existing data rather than initializing an empty array. var objs = component.get('v.objs'); objs.push(event.getSource().get("v.name")); component.set('v.objs', objs); Your ...
David Reed's user avatar
  • 93.2k
3 votes
Accepted

Delete an array element using event.getSource().get("v.name")

Aura:iteration has an attribute called as indexVar, why not use it? Also from Event docs: In the client-side controller, you can use one of the following methods to find out which button was ...
Pranay Jaiswal's user avatar
3 votes

How to pass dynamic arrays in Lightning

Why you don't want to use Lightning Controller. I don't think you can handle it without JS, as compiler won't let you save it(this is also your current behaviour). I suggest you create an array in JS ...
Tushar Sharma's user avatar
3 votes
Accepted

In JS of LWC, line after forEach statement does not execute

Looks to me like you are missing "this" references: .then(result => { this.apexJobInfoData = result.JobInfo.length===0?null:result.JobInfo; this.error = undefined; if(...
Phil W's user avatar
  • 37k
3 votes
Accepted

Update value in Array

You need to have an index value in your array - clonedGroupStructures. If you can iterate the array and add an index [ 0,1,2....] to it then you could be able to capture it from the input event. Once ...
SfdcBat's user avatar
  • 4,821
3 votes

Unable to pass an array from parent LWC to child LWC setter method

There is still one use case for @track. When a field contains an object or an array, there's a limit to the depth of changes that are tracked. To tell the framework to observe changes to the ...
Shagun Sharma's user avatar
3 votes
Accepted

How to set missing elements from the result in LWC

Please use below code in the wire function. It uses nullish coalescing operator to set default value if the value for that property is null or undefined. @wire(getData) datatable({ data, error }) { ...
Sneh's user avatar
  • 1,111

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