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 Answer
You simply need to specify the sobjectType
parameter (case sensitive) along with the case-sensitive fields.
Example:
public inherited sharing class Q341983 {
@AuraEnabled(cacheable=false)
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. May 3, 2021 at 8:56
-
-
-
@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 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.– sfdcfoxAug 29 at 12:17