I havent been able to find any sample js that clearly describes how to instantiate a new sobject from within a lightning component. Lets say I want to create a list of new custom sobjects named foo (that only have a name field) to pass into my server side controller for final DML – any ideas ?
I assume I would
have an aura:attribute on my component of name = fooList and type ='foo[]'.
Then from within my controller.js I would do a fooList = component.get("v.fooList")
but how do I then define a new sobject of type foo with name set, and push in instances of the sobject foo into fooList?
Any insights would be most appreciated.
Best Answer
You can certainly create a sobject instance in client and pass as it as array from the component and retrieve it as
List<sObject>
in the controller.If you want to pass a specific sObject type you, have to set the
sobjectType
.For eg:
sobjectType
toAccount
Here an simple example to do it.
TestApp:
TestAppController.js
Apex Controller: