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
Patrick McClellanPatrick McClellan 

when is recordId created?

I have a component that creates a form to enter Salesforce Certification Test Results, which provide section level scores. For example:

Test Taker: John Doe
Test Date: 08/02/2017
Exam: Administrator I

Section-Level Scores:
Organization Set-Up (Global UI): 100%
User Setup: 66%
Security and Access: 75%
Standard and Custom Objects: 77%
Sales and Marketing Applications: 75%
Service and Support Applications: 75%
Activity Management and Collaboration: 66%
Data Management: 100%
Analytics - Reports and Dashboards: 100%
Workflow/Process Automation: 80%
Desktop and Mobile Administration: 100%
AppExchange: 100%

When saved, I need to do the following:
  • Save the Exam name, User name, Exam date to a NEW Result__c record. Result__c is my PARENT object in a Master-Detail Relationship.
  • Create x number of child objects in Result_topic__c[], saving Topic Name, Score, and the recordID of the new result__c record. But that parent record is being created in the same operations (one form submission). 
I don't know where to derive the recordID number for the parent record that is being created at the same time. Does recordId get generated during the save operation, or is it generated when you hit the NEW button and open the form (that wouldn't be very efficient, but very useful in this situation.)

Anybody know where to look for an answer?
Hemant_SoniHemant_Soni
Hi Patrick McClellan,
It is very simple you need to insert first parent record which is Result__c and then you can insert Result_topic__c reocrds with then id of newly insert result and when you inserting Result__c first then it reocrdid is automatilly created.
If you are not getting my point then let me know.
Thanks
Hemant
Patrick McClellanPatrick McClellan
Hermant, thank you for your prompt reply. You have confirmed what I suspected, that the recordId is created automatically when the record is saved. So, following your advice, I'll need to do the following:
  1. Save the Exam name, User name, Exam date to a NEW Result__c record. Result__c is my PARENT object in a Master-Detail Relationship.
  2. Retrieve the recordID from that new record... or would that be provided in response.getReturnValue().id?
  3. Create x number of child objects in Result_topic__c[], saving Topic Name, Score, and the recordID of the new result__c record. But that parent record is being created in the same operations (one form submission). 
I'll try to test it...

Thanks again for your response!
Hemant_SoniHemant_Soni
Hi patrick,
I dont know your problem is solved or not.If your problem is not solved then share you code so i will make change in that.And then you can try to test.If you are not comfertable to share then we can connect on skype."sonihemant26" this is my skype id.
Thanks
Hemant
Patrick McClellanPatrick McClellan
Hi Hermant,

I've had to wait on testing this, as I'm dealing with another issue that happens before the save -- validating the form and getting the info ready to save. My issue is that the form is generated dynamically, using the aura:iterate. I'm doing that because each exam has a different number and set of topics.

I had written a detailed explanation of my issue, but in explaining it to you, I had a breakthrough -- so I'm redoing some of my code. I'll respond again when I can test some things.

THANK YOU -- this correspondence has facilitated a breakthrough!

Pat


 
Patrick McClellanPatrick McClellan
Hermant, 
I've tracked my issue down to the fact that when I'm iterating to create each ui.inputNumber on the form, I can't seem to dynamically set the aura:id. Without that id, I don't know a way to go back after the form is submitted and extract the input data. I'm going to start a new thread on this issue.
Patrick McClellanPatrick McClellan
Hermant, back to the original question. Since I'll need to do it in two steps, and the first step involves lookup fields which we can't use in Lightning components (yet -- they're working on adding them, according to Salesforce engineer at a user group meeting), I think I should use the standard New record form for the first part. So my next question is this: how do I pre-populate the parent object on the new child form?

As an example, using standard objects, if I created a new opportunity, then viewed that opportunity, I could see related list of products. Since it's a new opportunity, there are currently no related products listed, so I click NEW.

At this point, the form for new Opportunity Product opens, and the Opportunity parent object is pre-populated.

So if I were creating a custom component for new Opportunity product, how would I pre-populate the parent object?