Home SALESFORCEAPEX Upgrading Apex Classes for Custom Metadata Access: A Guide to API Version Compatibility

Upgrading Apex Classes for Custom Metadata Access: A Guide to API Version Compatibility

by Sakthivel Madesh

Introduction: Custom Metadata Types provide a flexible way to configure application settings and behavior in Salesforce. However, developers often encounter challenges when attempting to access Custom Metadata records in Apex classes, particularly when dealing with older API versions. In this blog post, we’ll explore the limitations of Custom Metadata access in older API versions and discuss the importance of upgrading Apex classes to ensure compatibility with the latest features.

Received the below error when the apex class version is below 49.0 when access custom meta data from apex class:

String endPoint =”;
endPoint = Mule_Settings__mdt.getInstance(‘SAPVersion’).EndPoint__c;

getInstance method is a new addition that is supported on api version v51.0 and above.

FATAL_ERROR System.TypeException: Unsupported sobject type and/or version

Understanding the Limitation: One significant limitation of accessing Custom Metadata Types in Apex classes is the version compatibility constraint. Prior to API version 49.0, direct access to Custom Metadata records in Apex classes was not supported. Even after version 49.0, certain methods like getInstance were introduced, enabling access to Custom Metadata records, but only for API version 51.0 and above.

Implications of Version Compatibility: For developers working with Apex classes using API versions below 49.0, accessing Custom Metadata records directly is not feasible. This limitation can hinder the implementation of dynamic configurations and customization in Salesforce applications, restricting developers to less flexible alternatives.

Solution: Upgrading Apex Classes To leverage the latest features and capabilities of Custom Metadata access in Apex classes, developers must upgrade their code to a compatible API version. In this case, updating the API version of the Apex class DealTriggerHandler to at least version 51.0 is necessary to utilize the getInstance method and access Custom Metadata records.

Updating Apex Class API Version:

  1. Open the Salesforce Developer Console or your preferred integrated development environment (IDE).
  2. Locate the APEX CLASS class in your Salesforce organization.
  3. Update the API version of the class declaration to 51.0 or higher.
  4. Save the changes to the class.

Or from Apex class meta.xml file:

<?xml version=”1.0″ encoding=”UTF-8″?>
<ApexClass xmlns=”http://soap.sforce.com/2006/04/metadata”>

Resources: For further guidance on upgrading Apex classes and understanding the latest features, refer to the Salesforce documentation on static accessor methods: Salesforce Release Notes – Static Accessor Methods

Conclusion: Ensuring compatibility with the latest Salesforce features is crucial for maximizing the capabilities of your Salesforce applications. By upgrading Apex classes to compatible API versions, developers can take advantage of enhancements like Custom Metadata access in Apex, empowering them to build more dynamic and customizable solutions. Stay updated with Salesforce releases and best practices to leverage the full potential of the platform in your development projects.

You may also like

Leave a Comment