1

I have been trying to understand custom metadata types in Salesforce, but there's still a lot of confusion on my end.

I understand that hardcoding record ids is not a best practice, and I would like to follow it as much as possible.

Meanwhile, I am planning to insert multiple combinations through custom metadata types. One text field will handle the id of an image stored in Files object. The value of this text field will be referenced in a formula field in a custom object that will display an image.

I know this will be possible through Apex, but I am concerned about the post deployment action of the custom medatada type as it is said that file ids vary from sandbox to production.

If this is the case, I will still have to modify file ids in custom metadata type when deployed in production. Is this action normal upon post deployment?

This is kind of confusing as I read somewhere that deployment with custom metadata type is less hassle compared to custom settings.

Hoping that someone with experience on it can enlighten me more about it.

Thanks in advance!

1 Answer 1

1

You should be choosing metadata for things that you intend to deploy and keep consistent among different environments. For clear and obvious reasons, that you mention, the ID will not be one of those things.

If you have to hardcode an ID, and have no choice to do so, you probably want to be looking at doing this via a Hierarchy Custom Setting (which you can still reference in a formula). It will also mean that you won't need to re-deploy or refresh sandboxes if you change the ID of the file in question.

However, you should do your utmost to avoid hardcoding an ID and instead perhaps agree on a naming convention for the file, that you can then query for. If you go that route, then CMTDT is your preferred vehicle since that name will indeed be consistent throughout your environments.

1
  • 1
    Thank you very much for the suggestion. Your explanation has been helpful. For the mean time, I will consider what approach to use first :)
    – Ertyq
    Commented Apr 24, 2020 at 0:29

You must log in to answer this question.

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