function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Chris Ciszak 22Chris Ciszak 22 

Loading a standard layout to create a new record and intercept the recordId after creation.

We are trying to create a standard salesforce record  directly from within our app. After the record is created, we should obtain the recordId and use it further in our application.

We have encountered problems to accomplish this in LEX.

There are two way to work with new records.
1. Use force:createRecord.
2. Use Lightning Data Service

However, the problem with force:createRecord is that we are unable to obtain the recordId after the creation as the user is directly redirected to the record's home page and there is no documented way to intercept this and obtain the recordId.

The problem with the Lightning Data Service is that it is unable to automatically render the object's entry standard layout, we need to manually specify fields which is a show stopper as it's required that the user are able to change the layout that will reflect in our application. The only place where Lightning Data Service load a form automatically is when we want to edit a record, not create one...

How can we accomplish the following:

1. Display a standard layout for a given object during the creation of the record.
2. Prepopulate some fields.
3. Collect recordId after the record is created.
4. Redirect user to our custom page so we could utilize the recordId.

Any help would be much appreciated.
Brian E MillerBrian E Miller
There is a third way to create new records, and that would be to use a custom helper function which calls an Apex controller to do the inserting.  In that @AuraEnabled method you can set the Id as the return type (or the whole SObject record, whereby you can access the Id easily).

See a sample of inserting a lead here: http://salesforce-walker.blogspot.co.il/2016/08/create-lead-record-using-lightning.html