Metadata

Apex Custom Metadata

Using Custom Metadata

Apex custom metadata stores configuration with SOQL queries.

What is Apex Custom Metadata?

Apex Custom Metadata is a powerful feature in Salesforce that allows developers to define and manage application configuration data. Unlike Custom Settings, Custom Metadata Types can be deployed to production environments and packaged, making them ideal for managing metadata-driven logic and configuration.

Benefits of Using Custom Metadata

Custom Metadata Types offer several advantages:

  • Version Control: Configuration changes can be tracked and deployed.
  • SOQL Queries: You can use SOQL queries to retrieve metadata records, making it easier to manipulate the data in Apex.
  • Deployment: Custom Metadata Types can be deployed between Salesforce orgs.

Creating a Custom Metadata Type

To create a Custom Metadata Type in Salesforce, follow these steps:

  1. Navigate to Setup.
  2. In the Quick Find box, type Custom Metadata Types.
  3. Click New Custom Metadata Type.
  4. Enter the required details such as Label and Object Name.
  5. Click Save.

Defining Fields for Custom Metadata

Once the Custom Metadata Type is created, you can define fields to store configuration data:

  1. Go to the detail page of the custom metadata type you just created.
  2. Under Custom Fields & Relationships, click New.
  3. Select the field type and enter the required details.
  4. Click Save.

Using SOQL to Query Custom Metadata

Custom Metadata records can be queried using SOQL. This enables you to access configuration data programmatically within your Apex code.

Accessing Custom Metadata in Apex

Once queried, Custom Metadata records can be used in Apex logic to drive application behavior based on configuration.

Conclusion

Apex Custom Metadata provides a robust way to manage configuration data with ease of deployment, versioning, and querying capabilities. By leveraging these features, developers can build more flexible and maintainable applications in Salesforce.

Metadata

Previous
Webhooks