0

Below is Lighting Component

<force:recordData aura:id="RecordCreator" 
                      recordId="{!v.recordId}"
                      layoutType="FULL"
                      targetRecord="{!v.newRecord}"
                      targetFields="{!v.simpleNewRecord}"
                      targetError="{!v.newRecordError}" 
                      fields=" Id, ParentId, custom_lookup__c"
                      />

Below id Controller.JS

component.set("v.simpleNewRecord.custom_lookup__c",component.get("v.userAccountInfo").Id);
    console.log("custom_lookup__c>>>"+component.get("v.simpleNewCase.custom_lookup__c"));
    component.set("v.simpleNewRecord.ParentId",component.get("v.Parent").Id);
    component.find("RecordCreator").saveRecord(function(saveResult) {  
                    if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
                           var resultsToast = $A.get("e.force:showToast");
                           resultsToast.setParams({
                           "title": "Saved",
                           "message": "The record is saved."
                           });
                           resultsToast.fire();
                     }

I am getting value in

console.log("custom_lookup__c>>>"+component.get("v.simpleNewCase.custom_lookup__c"));

Below is Lightning UI component

<aura:attribute name="userAccountInfo" type="Account"/>

<div class="slds-grid slds-gutters">
    <div class="slds-col slds-size_2-of-4" >
        <lightning:input aura:id="customlookup" label="customlookup Name" value="{!v.userAccountInfo.Name}" disabled="true"/>
    </div>
</div>

But when record detail page is opened custom_Lookup__c value is blank. Instead I am getting value for ParentId standard lookup field. It is not saving custom_lookup__c value. Can anyone please help.

  • Probably you have mapped the fields wrong in the lightning component UI. Please Share your input elements of the UI. – Santanu Halder Sep 7 '18 at 6:28
  • I updated post, I want that field to be pre-populated with account name. and then save accountid to that customlookup field on saving record – SFDCChallenge Sep 7 '18 at 6:50
  • also this is not correct as per mentioned code. console.log("custom_lookup__c>>>"+component.get("v.simpleNewCase.custom_lookup__c")); it should be console.log("custom_lookup__c>>>"+component.get("v.simpleNewRecord.custom_lookup__c")); – Gourishankar Sep 7 '18 at 7:36
0

you can check whether v.simpleNewRecord is having some value or not.It should not be null.

make sure you have defined the correct type for it.Just check the below sample code.

<aura:attribute name="boatReview" type="BoatReview__c" access="public"/>
<aura:attribute name="boatReviewRecord" type="Object" access="public"/>
 <force:recordData aura:id="service"
                  targetError="{!v.recordError}"
                  targetRecord="{!v.boatReviewRecord}"
                  targetFields="{!v.boatReview}"
                  fields="Id,Name,Comment__c,Boat__c"
                  recordUpdated="{!c.onRecordUpdated}"
                  />

in Controller you can do like this.

var rec = component.get("v.boatReview");
 alert("rec"+rec);
 component.find("service").saveRecord(function(saveResult) {
        if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
            if (!$A.util.isUndefinedOrNull(toast)) {
                toast.setParams({"title":"Saved",
                            "message":"The record was saved."}).fire();
            } else {
                alert("Successfully saved, question mark?");
            }
        } else {
            console.log('Error: ' + JSON.stringify(saveResult.error));
        }
    });
  • Hey I modified code so forgot to add updated aura:ID, Now its updated. – SFDCChallenge Sep 7 '18 at 7:16
  • Try the edited code and see whether you are getting value for v.simpleNewRecord.make sure its not null. – Gourishankar Sep 7 '18 at 8:04
  • On save I get all other field values except mentioned lookup field – SFDCChallenge Sep 7 '18 at 9:19
  • make sure you are doing component.get("v.simpleNewRecord.custom_lookup__c") and not component.get("v.simpleNewCase.custom_lookup__c"); – Gourishankar Sep 7 '18 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.