You need to sign in to do that
Don't have an account?
Mads Peter Rommedahl
How to have a Custom Metadata list and use it in Apex code?
Hey, I currently have an Apex function which takes a name and an existing Contact, and if the current Contact name is our dummy name 'Dyreven' but the new name is NOT it updates the Contact name. Like this:
However, instead of having the dummy name hardcoded in the Apex I want my Apex to pull a list of dummy names from custom metadata and then check through all of them. So it should be possible to have a custom list of dummy names and then the Apex code would check against that list instead of against a hardcoded String like above.
How can I do this? Are lists supported as a custom metadata type?
// Small method to check if the passed name variable is NOT 'Dyreven' but the current name is. Then replace 'Dyreven' with the new name private static Contact checkForUpdatedName(String name, Contact con){ if (name != 'Dyreven') { if (con.LastName == 'Dyreven') { con.LastName = name; update con; } } return con; }
However, instead of having the dummy name hardcoded in the Apex I want my Apex to pull a list of dummy names from custom metadata and then check through all of them. So it should be possible to have a custom list of dummy names and then the Apex code would check against that list instead of against a hardcoded String like above.
How can I do this? Are lists supported as a custom metadata type?
I think you are looking something similar to my bellow code sample.
I retrieved names from meta data Name_Data__mdt and added in a Set according to your use case.
All Answers
If you have only one string to compare then you can try below code.
I think you are looking something similar to my bellow code sample.
I retrieved names from meta data Name_Data__mdt and added in a Set according to your use case.
However, for my need I ended up simply using a CustomLabel, splitting the String along , and then I had a simple list of names to use
Yes our answer was based on custom metadata as you referred the same in question itself.
Enjoy Coding :)