Create and Manage Custom Metadata Types
- Declaratively create custom metadata types.
- Create custom metadata type fields.
- Create metadata records.
Create Custom Metadata Types
Acme Services offers different levels of support for accounts based on how much the account spends. Higher-level tiers are eligible for an extended warranty and extra discounts.
As the Salesforce admin, you create an app configuration that defines which tiers are available. You also need to deploy this app to your production org with all of its configurations. Sounds like a job for custom metadata types, which include both the metadata definitions and records. Go ahead and create a custom metadata type called Support Tier following these steps.
- From Setup, enter Custom Metadata Types in the Quick Find box and select Custom Metadata Types.
- Click New Custom Metadata Type.
- For Label, type Support Tier and for Plural Label, type Support Tiers.
After you save, you land on the Support Tier detail page where you can add custom fields and edit page layouts. We want our custom metadata type to associate each support tier with a minimum spending amount. We also want to include a default discount. Let’s create two custom fields.
Adding a custom field to a custom metadata type is just like adding a custom field to a standard or custom object. First, let’s create a field for the default discount.
- In the Custom Fields section, click New.
- Select Percent, then click Next.
- For Field Label, type Default Discount.
- For length, type 2.
- Click Next and then click Save.
Create another custom field, this time using Number as the field
type and Minimum Spending as the Field Label. For Length, type
6. For Field Manageability, make sure to select Any user
with the Customize Application permission (package upgrades won't overwrite the
Believe it or not, you finished creating your first custom metadata type. Let’s keep up the pace and start creating custom metadata records.
Create Custom Metadata Type Records
By itself, a custom metadata type isn’t useful. The value of custom metadata types is that you can create records that are defined by a type. So let’s do it!
- On the Support Tier detail page, click Manage Support Tiers.
- Click New.
- For the record label, type Bronze.
- For the Support Tier Name, type Bronze.
- For Default Discount, enter 0.
For Minimum Spending, enter 0.
Repeat this process until you have all of these values:
Master Label Default Discount (Custom Field) Minimum Spending (Custom Field) Bronze 0% 0 Silver 10% 1,000 Gold 15% 5,000
If you’re a developer, after you create these individual records you can build some custom functionality using SOQL and Apex to get your app working the way you need it to. (We cover some more technical aspects of using custom metadata types in the next module, so stay with us!)
Let’s see how to reference custom metadata type records in formulas, default values, and validation rules.