2

All I have a requirement to create a custom Case form with few fields. In Contact lookup, I am not able to see the option to create Contact. Can anyone guide me what I am missing in the code.

enter image description here

HTML:

<template>
<lightning-card>
<lightning-record-edit-form object-api-name="Case" onsuccess={handleSuccess} onsubmit ={handleSubmit}>
    <lightning-messages>
    </lightning-messages>
    <lightning-input-field field-name='ContactId'></lightning-input-field>
    <lightning-input-field field-name='Subject'></lightning-input-field>
    <lightning-input-field field-name='Description'></lightning-input-field>
    <lightning-input-field field-name='Origin'></lightning-input-field>
    <lightning-button class="slds-m-top_small" type="submit" label="Create Case">
    </lightning-button>
</lightning-record-edit-form>
</lightning-card>
</template>

Javascript:

import { LightningElement,api } from 'lwc';

export default class NewRecCreate extends LightningElement {
    handleSuccess(event) {
        console.log('onsuccess event recordEditForm',event.detail.id)
    }
    handleSubmit(event) {
        console.log('onsubmit event recordEditForm'+ event.detail.fields);
    }
}
2
  • 1
    That's all standard Salesforce UI, we don't get everything in the Standard LWC components, for this we have to write custom logic, create a custom LWC component which can do what lightning-input-field is doing for reference fields and then add option to allow New record. Feb 26, 2021 at 15:25
  • @itzmukeshy7 Thanks for your comment.
    – Tamil
    Feb 26, 2021 at 17:09

2 Answers 2

2

An extract from the documentation says:

Creating a new record from the lookup field's dropdown menu is currently not supported.

https://developer.salesforce.com/docs/component-library/bundle/lightning-input-field/documentation

0

I would check out this link.They are able to create a reusable lookup field. I would then append a value '+ New Record' that when selected opens a model to create a new record. Then you can capture the new record Id and place that into the lookup field.

You can also look at this example.

Either way, append an option to the drop down then look for onchange to see if that option was chosen then prompt the new record create.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .