1

I've created a custom LWC that is an SVG graphic used to replace a normal field. The idea is that the user can click the svg in different areas and it will update the field value in the background.

I've added it to the page layout in the Lightning App Builder.

The issue I'm having is that it only shows on the record detail page. When I add a new record or edit an existing record the component is missing from the form.

I've checked the meta file and have isExposed set to true and a target for Lightning__RecordPage.

I've tried search for anyone with the same issue, but just get lots of record_Edit_form posts that don't seem relevant.

Any help is appreciated.

Here is the code form my LWC in it helps

BCInput.js

import { LightningElement, api, wire, track } from 'lwc';
import { getRecord, getFieldValue, updateRecord } from "lightning/uiRecordApi";
import BC_FIELD from "@salesforce/schema/key_Player__c.BC_Status__c";
import ID_FIELD from "@salesforce/schema/Key_Player__c.Id";

const fields = [ID_FIELD,BC_FIELD];

export default class BCInput extends LightningElement {
    @api recordId;
    @track _bcValue;

    @wire(getRecord, { recordId: "$recordId", fields: fields })
    keyPlayer({data}) {
        this.value = getFieldValue(data, BC_FIELD);
    }

    updateBC(event) {

        const tmpfields = {};

        tmpfields[ID_FIELD.fieldApiName] = this.recordId;
        if (this.value === event.detail.message){
            tmpfields[BC_FIELD.fieldApiName] = null;
        }else{
            tmpfields[BC_FIELD.fieldApiName] = event.detail.message;
        }
        const recordInput = { fields: tmpfields };
        //console.log(JSON.parse(JSON.stringify(tmpfields)));
        updateRecord(recordInput);
    }

    get value() {
        return this._bcValue ;
    }
    set value(value) {
        this._bcValue = value;
    }
}

BCInput.html

<template>
    <div class="slds-form-element">
        <label class="slds-form-element__label" for="text-input-id-139">
          BC Status</label>
        <div class="slds-form-element__control bc">
            <c-b-c id="text-input-id-139" recordid={recordId} onbcclicked={updateBC} value={value} ></c-b-c>
        </div>
      </div>
</template>

BCInput.js-meta.xml

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>58.0</apiVersion>
    <isExposed>true</isExposed>
    <masterLabel>BC Input</masterLabel>
    <targets>
        <target>lightning__RecordPage</target>
    </targets>
</LightningComponentBundle>

1 Answer 1

1

The new and edit pages don't display certain kinds of content, including reports and custom components. Here, you can see an example account in my dev org. Notice the component I've circled:

Example component on page

However, if you try to create a new record, you'll see it doesn't render:

Creating a new Household Account

That's just how the UI works. If you really want to show custom components on a new/edit page, you'll have to use Standard Action Overrides. You would have to write a custom component or Visualforce page to render the entire form, including the custom components. This isn't impossible, but will require a non-trivial amount of work.

For now, I recommend voting on Custom components for rendering record fields from the IdeaExchange.

4
  • Thanks, I've upvoted the idea. I'll head down the route of a fully custom page. There are a few other things I'd need to show as well, so probably makes sense to go that way.
    – Andy
    Commented Nov 6, 2023 at 13:44
  • 1
    I saw indication, through the trailblazer community, that Salesforce already plan to add custom components to handle field display and editing. A "safe harbour" note was they were looking at 12-18 months, but that was about 12 months ago and I haven't seen any update. And, yes, sorry, I cannot find the posting in the community right now to share.
    – Phil W
    Commented Nov 6, 2023 at 14:14
  • @PhilW You can use custom components to override OmniScript fields. Were you thinking about that, maybe? Although I agree, it's likely they've been planning this feature for a while. It'd make sense to allow new data types and whatnot, and would also partly explain the push away from Classic. The old UI is barely hanging on by a thread these days.
    – sfdcfox
    Commented Nov 6, 2023 at 14:19
  • 1
    Actually, I found this update which suggested "Choose custom field display" (not yet editing) would be Winter 23 or after. Take a look at the attachment. I don't think this is the posting I found, since I recall commenting on the one I saw before.
    – Phil W
    Commented Nov 6, 2023 at 14:19

You must log in to answer this question.

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