I am getting an error that says, "Cannot add property count; the object is not extensible" while running LWC [duplicate]. Why is that?

248    Asked by dhanan_7781 in Salesforce , Asked on Sep 6, 2023

While running the given Javascript, an error is coming on the count and show records as I am adding an array into it. How do we resolve the error?

https://salesforce.stackexchange.com/questions/290122/this-error-is-coming-cannot-add-property-count-object-is-not-extensible-while

Answered by Asistha pandey

It seems that the response from Apex cannot be extended with additional parameters with Spring 20. Which means that the object is not extensible https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions For objects, you can use either result = object.assign({}, result)or item = object.assign({}, item)as a workaround for every item in result for arrays in a loop. You can also spread syntax data = { ...result };. There is another dirty hack, JSON.parse(JSON.stringify(result));.



Your Answer

Interviews

Parent Categories