0

I have a below array of objects in my LWC

   const lineItemsToUpdateArray =  [{"id":"a2323000000EWeRAAW","Licensed_User__c":"0032H00002HWXvzQAH","attributes":{"type":"Proposal_Line_Item__c","url":"/services/data/v57.0/sobjects/Proposal_Line_Item__c/a2323000000EWeRAAW"}}]

passing the above array to apex

await updateLineItems({lineItemsToUpdateArray })

passing the same JSON to apex

Apex code:

public static void updateLineItems(sObject[] lineItemsToUpdateArray) {

    update lineItemsToUpdateArray;
}

It throws below error

{"status":500,"body":{"message":"Unable to read SObject"},"headers":{},"ok":false,"statusText":"Server Error","errorType":"fetchResponse"}

Could someone please point me to the right direction?

3
  • I would start by double checking your permissions and API Version.
    – Adrian Larson
    Apr 19, 2023 at 15:56
  • I am system admin and have all the permissions required
    – gs650x
    Apr 19, 2023 at 15:59
  • Have you tried being more explicit about the property name, rather than using an inferred property name in the parameters object?
    – Phil W
    Apr 19, 2023 at 17:06

1 Answer 1

3

To send an SObject from LWC to Apex, you need to use the following format:

{
    "sobjectType": "Proposal_Line_Item__c",
    "Id": "a2323000000EWeRAAW",
    "Licensed_User__c": "0032H00002HWXvzQAH"
}

(Note: Id not id)

2
  • 1
    Or, alternatively, they could change that method to use Proposal_Line_Item__c[] as the parameter data type.
    – sfdcfox
    Apr 19, 2023 at 18:34
  • @sfdcfox I have tried that but it didn't work
    – gs650x
    Apr 20, 2023 at 3:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .