Newer Version Available
Saving Records
You can take advantage of the built-in create and edit record pages in Salesforce for
Android, iOS, and mobile web to create or edit records via a Lightning component.
The following component contains a button that calls a client-side controller to display the
edit record page.
The
client-side controller fires the force:recordEdit event,
which displays the edit record page for a given contact ID. For this event to be handled
correctly, the component must be included in Salesforce for Android, iOS, and mobile
web.
Records updated using the force:recordEdit event are persisted by default.
Saving Records using a Lightning Component
Alternatively, you might have a Lightning component that provides a custom form for users to add a record. To save the new record, wire up a client-side controller to an Apex controller. The following list shows how you can persist a record via a component and Apex controller.
Create an Apex controller to save your updates with the upsert operation. The following example is an Apex controller for upserting record data.
Call a client-side controller from your component. For example, <lightning:button label="Submit" onclick="{!c.createExpense}"/>.
In your client-side controller, provide any field validation and pass the record data to a
helper
function.
In your component helper, get an instance of the server-side controller and set a callback.
The following example upserts a record on a custom object. Recall that setParams() sets the value of the expense argument on the server-side controller’s saveExpense()
method.