You need to sign in to do that
Don't have an account?
PRUTHVI ADMIN
invalid mutation : [Object Object] is read-only
I am working on building an LWC component for a requirement. I would like to find a way to change/update the properties of an JavaScript Array that contains objects returned from Apex Controller. I tried below code, but there seems to be a javascript error. I tried many ways to change the properties of the object returned by Apex controller. But nothing worked. Code snippet & error details provided below. Can someone please help on this ?
JavaScript Error:
aura_proddebug.js:43117 Error: Invalid mutation: Cannot set "status" on "[object Object]". "[object Object]" is read-only. at ReadOnlyHandler.set (aura_proddebug.js:1100) at eval (showBiddersInTable.js:81) at Array.map () at ShowBiddersInTable.projectRolesFn (showBiddersInTable.js:79) at WireEventTarget.dispatchEvent (aura_proddebug.js:8329) at Object.next (lds.js:1157) at Subscription.next (lds.js:202) at FilterOnSubscribeBehaviorSubject._nextWithErrorHandling (lds.js:272) at eval (lds.js:304) at Set.forEach ()
public class FetchCPData { @AuraEnabled(cacheable=true) public static List<PRListWrapper> getPRList(String CPId) { List<PRListWrapper> prList = new List<PRListWrapper>(); for(PR__C pr : [SELECT Id, Status__c, Value__c, (select Id, Name from Opportunities__r limit 1) FROM PR__C WHERE PC__c=:CPId]){ PRListWrapper prw = new PRListWrapper(); prw.PRRecord = pr; if(!pr.Opportunities__r.isEmpty()) { prw.disable = true; }else { prw.disable = false; } prList.add(prw); } return prList; } public class PRListWrapper{ @AuraEnabled public Boolean disable; @AuraEnabled public PR__C PRRecord; } } import { LightningElement, api, wire, track} from 'lwc'; import getPRList from '@salesforce/apex/FetchCPData.getPRList'; const actions = [ { label: 'Delete', name: 'Delete' } ]; const columns = [ { label: 'Status', fieldName: 'status', editable:'true', type: 'text' }, { label: 'Bid Value', fieldName: 'value', editable:'true', type: 'currency', typeAttributes: { currencyCode: 'USD'}}, { type: 'action', typeAttributes: { rowActions: actions } } ] export default class ShowDataInTable extends LightningElement { @api recId; @track error; @track recSize; @track data = []; @track columns = columns; @wire(getPRList, { CPId : '$recId' }) projectRolesFn ({error , data}){ if(data){ const lostFilter = data.filter(element => { return element.PRRecord.Status__c!=='Lost'; }); this.data = lostFilter.map(element => { alert(element.PRRecord.Status__c); //This is fetching data as expected alert(element.PRRecord.Value__c); //This is fetching data as expected element.status = element.PRRecord.Status__c; //JavaScript error at this point(error given below) element.value = element.PRRecord.Value__c; return element; }); this.recSize = this.data.length; this.error = undefined; } else if(error){ this.error = error; this.data = undefined; } } }
JavaScript Error:
aura_proddebug.js:43117 Error: Invalid mutation: Cannot set "status" on "[object Object]". "[object Object]" is read-only. at ReadOnlyHandler.set (aura_proddebug.js:1100) at eval (showBiddersInTable.js:81) at Array.map () at ShowBiddersInTable.projectRolesFn (showBiddersInTable.js:79) at WireEventTarget.dispatchEvent (aura_proddebug.js:8329) at Object.next (lds.js:1157) at Subscription.next (lds.js:202) at FilterOnSubscribeBehaviorSubject._nextWithErrorHandling (lds.js:272) at eval (lds.js:304) at Set.forEach ()