You need to sign in to do that
Don't have an account?
Jaanu
Unable to save the record in lightning data services.
I am unable to save the record in LDS. can you pls help me.. Here is the component and controller.
Component
<lightning:recordEditForm recordId="{!v.recordId}" objectApiName="Prescription__c" >
<lightning:recordViewForm recordId="{!v.pacctId}" objectApiName="Account"> --> This is coming from Acct Object
<lightning:outputField fieldName="FirstName" />
<lightning:outputField fieldName="LastName" />
</lightning:recordViewForm>
<lightning:recordViewForm recordId="{!v.pacctId}" objectApiName="Pre__c"> --> This is coming from different Object
<lightning:outputField fieldName="P_First_Name__c" />
<lightning:outputField fieldName="P_Last_Name__c" />
</lightning:recordViewForm>
<div class="slds-p-horizontal--small">
<lightning:inputField fieldName="Name" /> --> These fields are input fields from 3rd Object which needs to be saved ultimately.
<lightning:input fieldName="D__c" />
<lightning:inputField fieldName="R__c" />
<lightning:inputField fieldName="O__c" />
</div>
<br/>
<lightning:layoutItem padding="around-small">
<lightning:button class="slds-button slds-button--brand" label="Next" onclick="{!c.handleSuccess}" variant="brand" />
</lightning:layoutItem>
controller
handleSuccess : function(component, event, helper) {
alert('I am in the Prescription success function # ' + component.get("v.pacctId"));
component.set("v.simpleInsertP.Pa__c", component.get("v.pacctId"));
component.set('v.simpleInsertPr.H_A__c', component.get("v.hcpId"));
alert(' I am here at 33333333 ....'); - > This alert is coming... after that nothing is happening... it's not even going to IF clause.
component.find("recordHandler").saveRecord(function(saveResult) {
if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
alert(' I am here at 2222222 ....');
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Success!",
"message": "Prescription Record created Successfully!",
"type": "success"
});
Component
<lightning:recordEditForm recordId="{!v.recordId}" objectApiName="Prescription__c" >
<lightning:recordViewForm recordId="{!v.pacctId}" objectApiName="Account"> --> This is coming from Acct Object
<lightning:outputField fieldName="FirstName" />
<lightning:outputField fieldName="LastName" />
</lightning:recordViewForm>
<lightning:recordViewForm recordId="{!v.pacctId}" objectApiName="Pre__c"> --> This is coming from different Object
<lightning:outputField fieldName="P_First_Name__c" />
<lightning:outputField fieldName="P_Last_Name__c" />
</lightning:recordViewForm>
<div class="slds-p-horizontal--small">
<lightning:inputField fieldName="Name" /> --> These fields are input fields from 3rd Object which needs to be saved ultimately.
<lightning:input fieldName="D__c" />
<lightning:inputField fieldName="R__c" />
<lightning:inputField fieldName="O__c" />
</div>
<br/>
<lightning:layoutItem padding="around-small">
<lightning:button class="slds-button slds-button--brand" label="Next" onclick="{!c.handleSuccess}" variant="brand" />
</lightning:layoutItem>
controller
handleSuccess : function(component, event, helper) {
alert('I am in the Prescription success function # ' + component.get("v.pacctId"));
component.set("v.simpleInsertP.Pa__c", component.get("v.pacctId"));
component.set('v.simpleInsertPr.H_A__c', component.get("v.hcpId"));
alert(' I am here at 33333333 ....'); - > This alert is coming... after that nothing is happening... it's not even going to IF clause.
component.find("recordHandler").saveRecord(function(saveResult) {
if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
alert(' I am here at 2222222 ....');
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Success!",
"message": "Prescription Record created Successfully!",
"type": "success"
});
I trust you are doing very well.
In order to use LDS you should use force:recordData component. To save a record using Lightning Data Service, call saveRecord on the force:recordData component, and pass in a callback function to be invoked after the save operation completes.
You can refer to below link for more information.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/data_service.htm
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/data_service_save_record.htm
Below is the sample code to save a record using LDS. Kindly modify it according to your requirement.
sObject : Customer__c
Fields : Name, Email__c, Address__c, Telephone__c
Component:
Controller:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in future.
Thanks and Regards,
Khan Anas
All Answers
I trust you are doing very well.
In order to use LDS you should use force:recordData component. To save a record using Lightning Data Service, call saveRecord on the force:recordData component, and pass in a callback function to be invoked after the save operation completes.
You can refer to below link for more information.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/data_service.htm
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/data_service_save_record.htm
Below is the sample code to save a record using LDS. Kindly modify it according to your requirement.
sObject : Customer__c
Fields : Name, Email__c, Address__c, Telephone__c
Component:
Controller:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in future.
Thanks and Regards,
Khan Anas
All my other components LDS is working fine ... for some reason ... this component is not going to the below if clause at all ... it's completely exiting the IF clause ...I have alert after the IF clause(after all ELSE clauses)...that's only coming ...
In this componet I am displaying fields from 2 objects (just output fields)... and input from one object.
if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
Did you copy-paste my code correctly?
Please share your complete code with the error message.
Regards,
Khan Anas
I did not work with your code ...I have psted my code above..do you see any issues with that please ?
In your code, I can't find <force:recordData> with aura:id="recordHandler"
I suggest you go through my code and you will definitely get the result.
Regards,
Khan Anas