I am using lightning:recordForm to create a record creation form. I am trying to pre-populate some fields.

My component:

    <aura:component description="replaceDuplicatesModal" controller="CustomModalController"
                implements="lightning:actionOverride, force:hasRecordId, force:hasSObjectName,force:appHostable,flexipage:availableForAllPageTypes"

  <aura:attribute name="sObjectName" type="String"/>
  <aura:attribute name="label" type="String"/>
  <aura:handler name="init" value="{! this }" action="{! c.init }"/>

My controller:

init: function (component, event, helper) {
                "aura:id": "form",
                "objectApiName": component.get('v.sObjectName'),
                "layoutType": 'Full',
                "mode": 'edit',
                'onload': component.getReference("c.handleOnLoad")
            function (recordForm, status, errorMessage) {
                //Add the new button to the body array
                if (status === "SUCCESS") {
                    var body = component.get("v.body");
                    component.set("v.body", body);
                else if (status === "INCOMPLETE") {
                    console.log("No response from server or client is offline.")
                    // Show offline error
                else if (status === "ERROR") {
                    console.log("Error: " + errorMessage);
                    // Show error message


handleOnLoad: function (component, event, helper) {

        var objectInfo = event.getParams().objectInfos;
        objectInfo["Metering_point_heat_meter__c"].fields['Metering_point__c'] = 'a0N6E000001RbzRUAS';

It Results in that that lookup field which i am trying to pre-populate, is searching.. and not responding to any activity. I am trying to show there the pre-populated value. Any ideas what i am doing wrong, or how this should be done? enter image description here

  • Hey were you able to find how to do this? – manza Sep 24 '18 at 23:55

In case this helps, as it is a workaround:

I was not able to set on load, but I was able to set it on submit based on This similar question, so if you can have as a work around hidding the field and set on submit this approach should work:

onRecordSubmit: function(component, event, helper) {
    event.preventDefault(); // stop form submission
    var eventFields = event.getParam("fields");
    eventFields["Field__c"] = "Test Value";

please consider that lightning:recordEditForm has an id in this case of aura:id="myform"

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.