Custom Metadata Type storage

From the Custom Metadata Type page under Setup, you can both create Custom Metadata Type objects and manage the records they contain. Any records you create can be included in your package and are thus available to your Apex logic immediately after the installation of your package.

Perform the following steps to create the Track Lap Records MDT object:

  1. Create a Track Lap Records Custom Metadata Type by clicking on New, and enter TrackLapRecords as the API name.
  2. From the Visibility field, select All Apex code and APIs can use the type, and it is visible in Setup. This is done since we want to allow the administrator to record their own fastest lap times in addition to those we include. You can choose the Only Apex code in the same managed package can see the type option if all records in this object are to be used only by your application logic, for example, for internal configuration.

  1. The page for describing your new Custom Metadata Type object looks very similar to that used by the Custom Object. As noted in the preceding table, you cannot define some features, such as Custom Buttons, though, in comparison to Custom Settings, you can define your own layout. There are also more field types available. The following screenshot shows what a Custom Metadata Type definition looks like:

You can see, in the preceding screenshot, that the API name for Custom Metadata Type objects ends with _mdt and has different standard fields. We will use the DeveloperName field as a unique name for the race track on which the lap record was achieved. Later, we will include records from this object in the package. The isProtected field is used to determine whether the recorded data can be edited by the administrator of the package.

Create fields on the TrackLapRecord_mdt object, as described in the following table, accepting the default shown for the Field Manageability field when you add each field. The following table lists the fields to create with their API name and field data type:

Object

Field name and type

TrackLapRecords__mdt

DriverName__c Text(60)

Time__c Number(5,3)

Year__c Text(4)

 

You may have noticed the following option when creating the preceding fields:

This option only applies with respect to records included in the package. It determines which fields the package administrator can change for those records. For example, you might want to add a Notes text field to the object that the administrator can edit, but protect all other fields. For the fields that we added here, the default setting is important because we want our package updates to update changes in new lap records on tracks known to the application. The following screenshot shows the fields that you previously created along with the Field Manageability status:

Using the information shown in the following screenshot, enter some sample data. To do this from the object definition page, click on Manage Track Lap Records to begin entering the configuration data. Deselect the Protected checkbox when adding records.

The Protected checkbox, displayed when creating records, determines whether the record is visible in the customer org. Protected records are hidden from the user, but your own packaged Apex code can still query them. It is a good idea to use protected records for internal configuration.

The following screenshot shows the sample data you should create:

Once you have created the sample data, you should see something similar to the preceding screenshot.

You can also define a List View to make it easier for you to manage Custom Metadata Type records in the Scratch org. You cannot initially edit the default All view, although you can create one with the same name; click on Create New View. This List View is not packaged.

Storage used by Custom Metadata Type records is not shown on the Storage Usage page. The calculation used is based on the maximum record size, which is based on the field size and not the standard 2 KB used on Custom Objects. Records created by users can total up to 10 MB. Your packaged records also get their own 10 MB limit. You can calculate the storage used by reviewing the record size shown on the Custom Metadata Types page. The following screenshot shows a summary of all Custom Metadata Type objects:

The preceding screenshot is a good way of determine the visibility and amount of data storage used by Custom Metadata Types. To add these records to the package, perform an sfdx force:source:pull command. This should download the following files to your /force-app/customMetadata folder:

└── force-app
└── main
└── default
└── customMetadata
├── TrackLapRecord.Circuit_Spa_Francorchamps.md-meta.xml
├── TrackLapRecord.Nurburgring.md-meta.xml
└── TrackLapRecord.Silverstone_Circuit.md-meta.xml

If you wish, you can now perform the commands discussed in Chapter 1, Building and Publishing Your Application, to build a new version of the package—this will now include the preceding Custom Metadata Type and records. When you install the package in your test org, you will see the records under the Setup menu option, Custom Metadata Types.

The Custom Metadata Type feature has an interesting history. In its pilot phase, the Custom Metadata Type feature was known as Platform on Platform. The branding later changed; however, at the time, Salesforce felt that this described the potential of this technology to start building your own platform packages that added new metadata types to the platform. As stated in the table in the Considerations for configuration data section, the ability for others to package your Custom Metadata Type records is a realization of this vision.

In this section, we created an object of Custom Metadata Type and created some records within it. Since track lap records are a form of predefined data, they are an ideal choice for Custom Metadata Types because records in such objects can be included in your package. The next section will explore a different type of configuration object type, Custom Settings.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.125.139