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
Matt Morris 24Matt Morris 24 

I have an idea to use custom metadata to dynamically change which user input fields are visible in a lightning component. Could this work?

I need a Quick Action (for mobile) to create a record of ObjectX from Contact (but ObjectX also has M-D to ObjectY). The user should also be presented with an ObjectX record type selector. Depending on the record type selected the user input screen shows different fields. On creation of ObjectX the user should be returned to the record created (not its parent).

Solution (so far)
Created a Flow which is called by the Quick Action - this presents the user (through a screen) a list of ObjectY records that are related to the Contact. User selects the ObjectY record. On the next screen there is a dynamic choice radio button that uses custom metadata records to indicate which (of the many) ObjectX record types should be available for the user to select.

So now I have the:
- Contact ID;
- ObjectY ID; and
- the desired Record Type ID of ObjectX.

All of this can be done in Flow. My next step is to have another screen that calls a (not yet created) Lightning Component that shows the right user input fields for the right ObjectX record type.

Proposed solution

Create another Custom Metadata object that has 5 fields:
- Label (text) - the name of the record type
- RecordTypeID (text) - the id of the record type
- Fields to Show (text) - a list of the ObjectX field api names seperated with semicolons. This is an ordered list of the fields to show on the input screen for this record type.
- Fields Required (text) - a list of the ObjectX field api names seperated with semicolons. This is a list of the fields that are to be shown that will be required for this record type.
- Fields Read Only (text) - a list of the ObjectX field api names seperated with semicolons. This is a list of the fields that are to be shown that will be read only for this record type.

A Lightning Component will take the 3 IDs from the flow, load the right Custom Metadata record and render the screen.
On save the new ObjectX record will be created and the user will be returned to this newly created record.

I would really appreciate some guidance on how I might create the Lightning Component that will be able to parse the Custom Metadata fields to generate the screen.

Thanks!