0

I have a custom object Child__c which looks up to Account. I am overriding New button of that Child__c. I am working in Classic and on click of New, I need to show some fields from Account and some fields from Child__c. I am using lightning-record-edit-form for this. Now what I am stuck at is I want to show a field of Child__c (Child_Field__c) as output field and I want to populate it's value from Account field. I already have the Account field value but don't know how I can instantiate Child__c and store the value I have in Child_Field__c and show as output field.

I Googled it and tried couple of links but it is not working.
https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.data_wire_example
Fetch Field Label in Lightning Web Components

Can anyone suggest how to do it?

0

You can make use of value attribute of lightning-input-field to prepopulate a field with default value and use disabled attribute to make it read only.

<template>
    <lightning-record-edit-form object-api-name="Child__c">
        <lightning-messages></lightning-messages>
        <lightning-input-field field-name="Account__c"></lightning-input-field>
        <lightning-input-field field-name="Child_Field__c" value={valueFromAccount} disabled></lightning-input-field>
        <lightning-button class="slds-m-top_small" variant="brand"
            type="submit" name="update" label="Update">
        </lightning-button>
    </lightning-record-edit-form>        
</template>
4
  • Hi Sanket, I appreciate it and tried this, but it is showing grey colored background for disabled text box and I also have a lookup field of account. It shows as grey background and account icon. I can make the change from CSS but while this is a hack, we have a whole team checking for the best practices. So, do you have any other solution to this? – Jigar Trivedi Oct 7 '20 at 8:58
  • And if we try to modify the CSS by adding a .css file, LWC has limitation. Just saw this article. salesforce.stackexchange.com/questions/279878/… – Jigar Trivedi Oct 7 '20 at 9:25
  • accepted the answer as there seem to be no alternate to this at the moment. Thank you for answering and for your blogs as well! Really appreciate it. – Jigar Trivedi Oct 7 '20 at 13:02
  • Thank you @JigarTrivedi – sanket kumar Oct 7 '20 at 14:20

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.