Start tracking your progress
Trailhead Home
Trailhead Home

Create and Manage Custom Metadata Types

Learning Objectives

After completing this unit, you’ll be able to:
  • 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.

  1. From Setup, enter Custom Metadata Types in the Quick Find box and select Custom Metadata Types.
  2. Click New Custom Metadata Type.
  3. For Label, type Support Tier and for Plural Label, type Support Tiers.
  4. Click Save.

    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.

  5. In the Custom Fields section, click New.
  6. Select Percent, then click Next.
  7. For Field Label, type Default Discount.
  8. For length, type 2.
  9. Click Next and then click Save.
  10. 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 value).

    The custom metadata type custom fields created in the previous steps.

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!

  1. On the Support Tier detail page, click Manage Support Tiers.
  2. Click New.
  3. For the record label, type Bronze.
  4. For the Support Tier Name, type Bronze.
  5. For Default Discount, enter 0.
  6. 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.