📢 Attention Salesforce Certified Trailblazers! Maintain your credentials and link your Trailhead and Webassessor accounts by December 6th. Learn more.
close
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. Search Setup for Custom Metadata Types.
  2. Click New Custom Metadata Type.
  3. 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.

  4. Under Custom fields, click New.
  5. Select Percent and for Field Label type Default Discount.
  6. For length, type 2.
  7. Click Next and then click Save.
  8. 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. Call your record Bronze.
  4. For Minimum Spending, enter 0.
  5. For Default Discount, enter 0.
Repeat this process until you have all of these values.
Master Label Minimum Spending (Custom Field) Default Discount (Custom Field)
Bronze 0 0%
Silver 1,000 10%
Gold 5,000 15%

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.