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
Ramy Higazi 4Ramy Higazi 4 

Custom Metadata Types convert IDs in Sobject names

Dear Sir and Madam,

we have setup "Custom Metadata Types" for configuration in our program.

Custom Metadata Type called:
Bauobjekt Field Mapping

SELECT ibszpbaucore__Bauobjekt_Entity__c,ibszpbaucore__Bauobjekt_Feld__c,ibszpbaucore__Bauobjekt_Lead_Entity__c,ibszpbaucore__Bauobjekt_Lead_Feld__c,Id FROM ibszpbaucore__Bauobjekt_Field_Mapping__mdt


when I check the data in this table I see that the following view:


ibszpbaucore__Bauobjekt_Entity__c ibszpbaucore__Bauobjekt_Feld__c ibszpbaucore__Bauobjekt_Lead_Entity__c ibszpbaucore__Bauobjekt_Lead_Feld__c Id
1 01I0Y000000bG6s 01I0Y000000bG6s.00N0Y00000EpS1x 01I0Y000000bG64 01I0Y000000bG64.00N0Y00000GGgWW m000Y000000DlJfQAK
2 01I0Y000000bG6s 01I0Y000000bG6s.00N0Y00000EpS27 01I0Y000000bG64 01I0Y000000bG64.00N0Y00000GGgWg m000Y000000DlMZQA0
3 01I0Y000000bG6s 01I0Y000000bG6s.00N0Y00000EpSDf 01I0Y000000bG64 01I0Y000000bG64.00N0Y00000GGgaE m000Y000000DlMoQAK
4 01I0Y000000bG6s 01I0Y000000bG6s.00N0Y00000EpSCm 01I0Y000000bG64 01I0Y000000bG64.00N0Y00000GGgWq m000Y000000DlJkQAK
5 01I0Y000000bG6s 01I0Y000000bG6s.00N0Y00000EpSIH 01I0Y000000bG64 01I0Y000000bG64.00N0Y00000GGgaJ m000Y000000DlMtQAK
6 01I0Y000000bG6s 01I0Y000000bG6s.00N0Y00000EpSCr 01I0Y000000bG64 01I0Y000000bG64.00N0Y00000GGgWv m000Y000000DlJpQAK

Result in Documentation:
https://developer.salesforce.com/blogs/developer-relations/2017/04/simplify-salesforce-data-custom-metadata-type-relationships.html


all Fieldnames are reflected by ID instead by name.
How can I convert them by apex to real names?
Are these Ids stored while packaging and how will this info be available on other Systems,
if transfered, or do I have to customize again?
thank you for your help
Best Answer chosen by Ramy Higazi 4
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello Ramy,

If the fields that you are querying are relationship metadate fields, all you need is to query the MasterLabel or any other field you want from the related record. Here is an example:
 
Child__mdt child = [SELECT Parent__c, Parent__r.MasterLabel FROM Child__mdt LIMIT 1];

// The parent Id
system.debug(child.Parent__c);

// The parent label
system.debug(child.Parent__r.MasterLabel);

To undesrtand more about relationship queries I recommend you this reading:
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_understanding.htm#sforce_api_calls_soql_relationships_understanding (http://​https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_understanding.htm#sforce_api_calls_soql_relationships_understanding)

Regarding the deployment, one of the advantages of Custom Metadata is that when you deploy all records goes with it so you don't have to input the values again. Unless you are storing sensitive information, such as, hardcoded Ids which I highly recommend you not to do.

Related info:
https://help.salesforce.com/articleView?id=custommetadatatypes_changesets.htm&type=0&language=en_US (http://​https://help.salesforce.com/articleView?id=custommetadatatypes_changesets.htm&type=0&language=en_US)
https://help.salesforce.com/articleView?id=custommetadatatypes_overview.htm&type=0

Hope to have helped!

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
 

All Answers

Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello Ramy,

If the fields that you are querying are relationship metadate fields, all you need is to query the MasterLabel or any other field you want from the related record. Here is an example:
 
Child__mdt child = [SELECT Parent__c, Parent__r.MasterLabel FROM Child__mdt LIMIT 1];

// The parent Id
system.debug(child.Parent__c);

// The parent label
system.debug(child.Parent__r.MasterLabel);

To undesrtand more about relationship queries I recommend you this reading:
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_understanding.htm#sforce_api_calls_soql_relationships_understanding (http://​https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_understanding.htm#sforce_api_calls_soql_relationships_understanding)

Regarding the deployment, one of the advantages of Custom Metadata is that when you deploy all records goes with it so you don't have to input the values again. Unless you are storing sensitive information, such as, hardcoded Ids which I highly recommend you not to do.

Related info:
https://help.salesforce.com/articleView?id=custommetadatatypes_changesets.htm&type=0&language=en_US (http://​https://help.salesforce.com/articleView?id=custommetadatatypes_changesets.htm&type=0&language=en_US)
https://help.salesforce.com/articleView?id=custommetadatatypes_overview.htm&type=0

Hope to have helped!

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
 
This was selected as the best answer
drs-medrs-me
Hi Zuinglio,
I think what Ramy meant was, that he crated a custom metadata type with the type of field.
If he query this table and entered a custom field in that field, then he got an ID instead the name of the field itself.
drs-medrs-me
Hi Zuinglio,
Now I got what you meant, so instead of doing this query:

SELECT myfielddefinition__c FROM settings_mdt
we do
SELECT myfielddefinition__r.MasterLabel FROM settings_mdt
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello Donny,

Yes! I hope you've managed to solve it.

Hope to have helped!

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
Ramy Higazi 4Ramy Higazi 4
SOLVED