Creating a new record

To create a new record, find the force:recordData component and use the getNewRecord() function to initialize sObject. It is usually better to initialize the object in the init handler of the component.

The component code and controller to initialize the sObject for the force:recordData is shown as follows. The following example assumes that we are creating a simple Lead record in Salesforce:

<aura:component implements="flexipage:availableForRecordHome, force:hasRecordId"><aura:handler name="init" value="{!this}" action="{!c.doInit}"/><aura:attribute name="newLead" type="Object"/><aura:attribute name="recordError" type="String"/>    <force:recordData aura:id="recordComponent"          layoutType="FULL" targetFields="{!v.newLead}" ...

Get Learning Salesforce Lightning Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.