You need to sign in to do that
Don't have an account?

Lightning Component Using <Force:inputField> Not Working Properly
Component Code
Controller Code
Helper Code
This Code is working only upto the page,but its not saving the the account when ever i click the create account button,but if i remove the force inputfield the account is getting created.
<aura:component controller="AccountController11"> <aura:attribute name="newAccount" type="Account" default="{ 'sobjectType': 'Account', 'Name': '', 'Type': '', 'Industry': '', 'ParentId':'', }"/> <aura:attribute name="Type" type="List" /> <aura:handler name="init" value="{!this}" action="{!c.loadOptions}" /> <force:outputField aura:id="accountLookupOutput" value="{!v.newAccount.ParentId}" class="slds-hide"></force:outputField> <aura:attribute name="accounts" type="Account[]"/> <form class="slds-form--stacked"> <lightning:input aura:id="accountform" label="Account Name" name="Accountname" value="{!v.newAccount.Name}" required="true"/> <lightning:select name="select" label="Select a Account Type" required="true" messageWhenValueMissing="Did you forget to select Account Type?" value="{!v.newAccount.Type}"> <option value="">-- None --</option> <aura:iteration items="{!v.Type}" var="T1"> <option value="{!T1}" text="{!T1}"></option> </aura:iteration> </lightning:select> <force:inputField aura:id="accountLookup" value="{!v.newAccount.ParentId}"></force:inputField> <lightning:button label="Create Account" class="slds-m-top--medium" variant="brand" onclick="{!c.clickCreate}"/> </form> </aura:component>
Controller Code
({ loadOptions: function(component, event, helper) { var action=component.get("c.accountType"); action.setCallback(this, function(response){ component.set("v.Type",response.getReturnValue()) }); $A.enqueueAction(action); }, clickCreate : function(component, event, helper) { var newAccount=component.get("v.newAccount"); console.log(newAccount); if($A.util.isEmpty(newAccount.Name) || $A.util.isUndefined(newAccount.Name)){ alert(' Name is Required'); return; } console.log("Create Account: " + JSON.stringify(newAccount)); var b=JSON.stringify(newAccount); console.log("Create Account:"+JSON.parse(b)); helper.createAccount(component,newAccount); } })
Helper Code
({ createAccount: function(component, acc) { var action = component.get("c.saveAccount"); console.log(acc); action.setParams({ "acc1": acc }); action.setCallback(this, function(response){ var state = response.getState(); if (state === "SUCCESS") { var accounts = component.get("v.accounts"); accounts.push(response.getReturnValue()); component.set("v.accounts", accounts); } }); $A.enqueueAction(action); } })
This Code is working only upto the page,but its not saving the the account when ever i click the create account button,but if i remove the force inputfield the account is getting created.
try this for lookup field
http://sfdcmonkey.com/2017/01/07/custom-lookup-lightning-component/
https://help.salesforce.com/articleView?id=000268561&language=en_US&type=1