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
Pradeep Musthi 9Pradeep Musthi 9 

Lightning Component Using <Force:inputField> Not Working Properly

Component Code
<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.
Pradeep Musthi 9Pradeep Musthi 9
Controller code
public class AccountController11 {
@AuraEnabled
     public static List<String> accountType() {
     Schema.DescribeFieldResult fieldResult =Account.Type.getDescribe();
     List<Schema.PicklistEntry> ls=fieldResult.getPicklistValues();
     List<String> options = new List<String>();
     for( Schema.PicklistEntry f : ls)
     {
      options.add(f.getLabel());
     }       
     return options;
    }
@AuraEnabled
     public static Account saveAccount(Account acc1) {
        // Perform isUpdatable() checking first, then
        //acc1.Type=Atype;
        system.debug(acc1);
        upsert acc1;
         system.debug(acc1);
        return acc1;
     }

}

 
NanduNandu
Hi Pradeep Musthi 9,
try this for lookup field 
http://sfdcmonkey.com/2017/01/07/custom-lookup-lightning-component/
Raj VakatiRaj Vakati
Refer this link for workaround .. you no need to create a custom lookup cmp 

https://help.salesforce.com/articleView?id=000268561&language=en_US&type=1