March 26, 2018

Lookup field with option to create new record in Custom Lightning Component

Sample Code:

<aura:component implements="force:appHostable" >

     <aura:attribute name="oppty" 
                    type="Opportunity" 
                    default="{ 'sobjectType': 'Opportunity'}"/>
    
    <div class="slds-box slds-theme_default">
        Account : <force:inputField value="{!v.oppty.AccountId}"/>
    </div>
    

</aura:component>

Output:


9 comments:

  1. how to create Multi select Lookup field with option to create new record in Custom Lightning Component?

    ReplyDelete
    Replies
    1. You have to create a custom search page so that you can select multiple using check boxes instead of lookup field. You have to use wrapper kinda design.

      Delete
  2. click New account open the new account record page

    ReplyDelete
    Replies
    1. Yes. That's how it works. If you want to search for accounts, enter the keyword and click search icon on the right.

      Delete
    2. on click New Account is not open the new account record page.....!

      Delete
    3. Check whether you are getting any errors in the Browser Console.

      Delete
  3. Drop down is not in correct position on scroll, Please help to fix

    ReplyDelete
    Replies
    1. Adjust the width of the div to double check.

      Delete
    2. Thanks Mugulan Duraipandian, Found solution by making the parent div position:relative.https://salesforce.stackexchange.com/questions/316175/forceinputfield-lookup-field-with-create-new-record-option

      Delete