Andy in the Cloud

From BBC Basic to Force.com and beyond…

14 thoughts on “Building Robust Dynamic Code with Custom Metadata Field Relationships

  1. Is there anything else required to activate the field definitions .It only shows entity definitions and I am on Spring 17 org

  2. Hi Andy,
    Thank you for this great article on this feature. Also thanks for the various links which are highly useful for understanding the concept. I was always wondering why did Salesforce release Custom Metadata when there is Custom Settings; now I have stronger points to support.

    • No worries Abhilash, glad it help express the value for you. Metadata Relationships have really given the feature a “value” boost for sure!

  3. Another cool use case for this is to define a list of fields via a set of custom metadata type rows that should be cleared on a clone operation. Often one has ‘system-y’ type fields created by triggers/workflows that simply don’t apply on a clone operation (for example, cloning an Opportunity and clearing the PO_Number__c field). The admin can add to the list of __mdt rows without ever having to touch the underlying apex code

  4. Hi Andy,

    I am unable to have the look up icon shoe up on the custom UI page, the doesnt seem to work. Also I am trying to show the Developer name of in the reference field instead of the record ID. Any thoughts?

    • Sorry I am not sure of the context of your question here? What are you doing?

      • I am so sorry that my comment was not neatly constructed.

        I am unable to have the look up icon show on the custom UI page. The binding doesn’t seem to work. I am being forced to use while attempting to show the Developer name of the reference field instead of the record ID which is currently showing up. Further, on save or update on the record from the UI, it throws an error, invalid reference field and is unable to save the record(But the ID in the reference field is the correct ID to the related metadata type).

        I have built my UI based off one of ur posts about custom UI for Custom Metadata Type. My understanding is the code in that post was to support v34.0 and relationships came out with v39.0. We are trying to generate a new Metadata Service Class from the Metadata API, but are having trouble saving it. Do you have any ideas on on implementing the look up icon on the VF page?

      • I see, so sadly VF apex:inputField is not supported with Custom Metadata Typre fields. So you cannot get the usual lookup icon to display with MD relationships. You will have to build your own drop down list box.

  5. There is still some limitations re metadata relationships. When you need to query with WHERE criterion, filtering just by object works well, but filtering by field name (alone or in junction with object condition) throws an error: ‘Query is either selecting too many fields or the filter conditions are too complicated.’
    Example of a query I’m talking about:
    select Id from CustomLookupName__mdt where Object__r.QualifiedAPIName = ‘AccountAddress__c’ AND Field__r.QualifiedAPIName = ‘AddressLine1__c’

    So we need to consider all pros and cons before switching from text fields to metadata relationships. In my case it doesn’t work, because of this limitation, that’s why I still stick just to text fields.

  6. Hey Andy,

    Need your suggestion on this one!

    I have a requirement to auto-populate a few fields from a record in its record name. I am doing this via a custom metadata and apex.
    There are multiple record types for this record and each record type has a set of different fields that need to be populated in its name.

    For example:
    Record Type1 should have Name as Field1 – Field2 – Field3
    Record Type2 should have Name as Field4 – Field5 – Field6

    The problem is when I create a record for the custom metadata, I can only create one record per object. But I need to create two records per object for each record type. How do I do this? Below is the error I get. Many thanks Andy 🙂

    Custom Object Naming Setting
    Error: Invalid Data.
    Review all error messages below to correct your data.
    Label: Micro Account Name
    Custom Object Naming Setting Name: Micro_Account_Name
    Object Name : Products_Services__c
    Error: Duplicate value on record: Energy Account Name
    Fields: Supply_Address_New__c;Generation_Type__c
    Record Type Names: Feed in Tariff;Forest Green Sun

    ‘Energy Account Name’ is a record I created for this metadata to populate different fields for a different record type.

    • You will need to set unique DeveloperName field value for each record. It’s not clear how your building your UI for this, is it intended to edit multiple records at a time?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s