I need to pass the record to the Apex controller from Lightning Web Component. What would be the best way to pass the sobject record?

  • 1
    Please edit your post to show what you've tried and where you're stuck, including your actual code.
    – David Reed
    May 3, 2021 at 17:19

1 Answer 1


You simply need to specify the sobjectType parameter (case sensitive) along with the case-sensitive fields.


public inherited sharing class Q341983 {
  public static void createRecord(sObject record) {
    insert record;

const record = {
  sobjectType: "Account",
  Name: "Demo",
createRecord({ record })
  .then(() => alert("record created"))
  .catch((error) => alert("error: " + JSON.stringify(error)));

  • hey @sfdcfox, Thanks for your reply. In our case, we are dealing with a record update.
    – Ravi Teja
    May 3, 2021 at 8:56
  • @RaviTeja It's Id, not ID. JavaScript is cAsE-sEnSiTiVe.
    – sfdcfox
    May 3, 2021 at 11:47
  • @sfdxfox, Thanks for your help! :)
    – Ravi Teja
    May 4, 2021 at 7:28
  • @sfdcfox I was actually just trying to do the same and it wasn't until I stumbled upon this post that I realized that 'sobjectType' is a necessary field to include in the parameter object. Got an error that sObject can't be read otherwise. Do you maybe have any reference to the official documentation that sheds some light on this? Aug 29, 2023 at 12:06
  • @MichaelMunta My apologies, but I can't seem to find it. I know I've seen it in the docs or an example somewhere, but it's really hard to search for it, since it's a very common term in Salesforce. I'm a collector of a bunch of fringe Salesforce knowledge, but I don't always remember where I get the facts from.
    – sfdcfox
    Aug 29, 2023 at 12:17

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