Skip to main content
Group

Apex Metadata API

Generally Available Features • Retrieve synchronously • Create and Update via asynchronous deploy • Callback on completion • Metadata types supported •• Records of custom metadata types •• Page layouts • Trusted apps only •• Installed package is “ApexCertified” or •• Sub org has setting enabled • Audit history tracks namespace Next priorities (Forward Looking Statement disclaimer applies) • Track deploy status (deployJobId) • Support more metadata types •• Picklist values •• Custom fields •• etc. (use this group to tell us which you need) Note that we plan to add support for “Delete,” but it is not the top priority.

There hasn't been a single update to the Apex Metadata API since its introduction years ago. It is still missing critical features like custom metadata type record deletes or synchronous custom metadata type record dml, that are required to actually make the feature usable.

2 answers
  1. Nov 24, 2025, 4:41 PM

    Maybe if we rename it Agentforce Metadata API then someone will prioritize it.

0/9000
0/9000

Greetings! I know this has been asked before, but haven't seen anything too recent.  Any plans on giving us the ability to retrieve Picklist Values for a specified Record Type?  That would be so helpful to me at the moment.  Unfortunately, I can't wait and am currently doing the MetadataAPI callout using named credentials work-around as I need it within a LWC.

1 answer
0/9000

Resources from the Salesforce Developers Ask Me Anything on What’s Coming with Salesforce Eventing

 

I hope you joined us for the fantastic #SFDevsAMA on Wednesday 28 August 2024 featuring @Philippe Ozil with product experts @Raj Advani and @Tyson Read. They loved answering your questions about What’s Coming with Salesforce Eventing. If you missed it, don't worry - we recorded the series and our experts have provided some great resources that our experts for you to continue your learning! 

 

Still have questions? Post them in this thread for our experts!

 

#Ask An Expert #CommUpdates #Integration #Automation #Platform Events #Salesforce Platform

 

@Official: Platform Events @* Salesforce Platform * @Trailblazer Community Cove @Apex Metadata API

1 comment
  1. Aug 28, 2024, 6:29 PM

    Thanks so much for all the great questions, folks! It was great hearing from you

0/9000

We're trying to revamp our sandbox refresh processes.

 

I originally tried to implement a solution using custom metadata types, but I believe I've run into a limitation that the SandboxPostCopy Interface Method cannot reference/update CMDT (but it can reference/update custom settings).

 

Therefore, I was directed to use Custom Settings, which have obvious limitations...

 

As I was about to begin the custom settings approach, I came across the Apex Metadata API group. It doesn't look like this API is currently being further developed, but maybe it can help with my current use case.

 

I also came across this UnofficialSF component that may have some potential for my use case (I'm trying to get justification with my ops team to try it in our dev org): https://unofficialsf.com/save-and-update-custom-metadata-records-using-flow/

https://github.com/jongpie/CustomMetadataSaver

 

My resulting question: Can the SandboxPostCopy Interface work together with the Apex Metadata API to update custom metadata settings in a sandbox, post refresh? I've seen some mention about a session ID is required to use the Apex Metadata API, and that the SandboxPostCopy Interface uses a special user without a session ID.

3 answers
  1. Jul 9, 2024, 1:37 PM

    Sushil and Frans,

     

    Thank you for the great perspective here.

     

    At this time, we're only at the design aspect of our eventual solution. We hadn't run into an actual conflict / blocker yet, but I ran into this post mentioning it wasn't possible to utilize custom metadata in the SandboxPostCopy Interface. After seeing that, I went to Salesforce support, and they confirmed the SandboxPostCopy Interface could not directly reference custom metadata, but it looks like the support agent was unaware of the Apex Metadata API. 

     

    I am going to update the relevant idea Salesforce support made for me, as well as the post I referenced above, to point them here that this can be done using the Apex Metadata API. Once we develop our solution, I'll plan to report back as well. 

     

    Best,

     

    Jack 

0/9000

Hi ,

I need the attachment_url ,under attachment attribute.

How to get this attachment_url value using apex

My Sample JSON :

    "ticket_cc_emails": [],

    "fr_escalated": false,

    "spam": false,

    "email_config_id": null,

    "group_id": 72000320936,

    "priority": 1,

    "requester_id": 72012786963,

    "responder_id": 72010582985,

    "source": 2, 

    "status": 5,

    "subject": "Updated ACP Capacity", 

    "id": 54942,

    "type": "SE Scheduler",

    "due_by": "2024-04-11T12:27:12Z",

    "fr_due_by": "2024-04-06T13:57:12Z",

    "is_escalated": false,   

    "custom_fields": {

        "cf_class75953": "Configuration",

        "cf_subclass650579": "Availability",

        "cf_class832453": null,

        "cf_subclass605425": null,

        "cf_billing_subclass": null,

        "cf_test": null,

        "cf_connect_type": null,

        "cf_connect_subtype": null,         

        "cf_subclass": null,   

        "cf_priority": false

    },

    "created_at": "2024-04-05T16:26:34Z",

    "updated_at": "2024-04-08T13:24:00Z",

    "tags": [

        "SP Post Launch Adoption"

    ],

    "attachments": [

        {

            "id": 72092546835,

            "content_type": "image/png",

            "size": 106213,

            "name": "Screenshot 2024-03-22 134756 (1).png",

            "attachment_url": "https://s3.amazonaws.com",

            "created_at": "2024-04-05T16:26:34Z",

            "updated_at": "2024-04-05T16:26:34Z"

        }

    ],

    "source_additional_info": null, 

    "nr_due_by": null,

    "nr_escalated": false

}Show Less

1 answer
  1. May 11, 2024, 1:29 PM

    Hi @titan blazers,

    Hope you are doing well,

    To extract the attachment_url value from the JSON string in Apex, you can use the JSON.deserializeUntyped method to convert the JSON string into a map, and then traverse the map to access the desired attribute. Here's how you can do it:

    String jsonString = '{ "ticket_cc_emails": [], "fr_escalated": false, "spam": false, "email_config_id": null, "group_id": 72000320936, "priority": 1, "requester_id": 72012786963, "responder_id": 72010582985, "source": 2, "status": 5, "subject": "Updated ACP Capacity", "id": 54942, "type": "SE Scheduler", "due_by": "2024-04-11T12:27:12Z", "fr_due_by": "2024-04-06T13:57:12Z", "is_escalated": false, "custom_fields": { "cf_class75953": "Configuration", "cf_subclass650579": "Availability", "cf_class832453": null, "cf_subclass605425": null, "cf_billing_subclass": null, "cf_test": null, "cf_connect_type": null, "cf_connect_subtype": null, "cf_subclass": null, "cf_priority": false }, "created_at": "2024-04-05T16:26:34Z", "updated_at": "2024-04-08T13:24:00Z", "tags": [ "SP Post Launch Adoption" ], "attachments": [ { "id": 72092546835, "content_type": "image/png", "size": 106213, "name": "Screenshot 2024-03-22 134756 (1).png", "attachment_url": "https://s3.amazonaws.com", "created_at": "2024-04-05T16:26:34Z", "updated_at": "2024-04-05T16:26:34Z" } ], "source_additional_info": null, "nr_due_by": null, "nr_escalated": false }';

     

    // Deserialize the JSON string into a map

    Map<String, Object> jsonMap = (Map<String, Object>) JSON.deserializeUntyped(jsonString);

     

    // Extract the 'attachments' array from the map

    List<Object> attachments = (List<Object>) jsonMap.get('attachments');

     

    // Check if attachments exist

    if (attachments != null && !attachments.isEmpty()) {

        // Extract the first attachment object

        Map<String, Object> attachment = (Map<String, Object>) attachments[0];

        

        // Extract the 'attachment_url' attribute from the attachment object

        String attachmentUrl = (String) attachment.get('attachment_url');

        

        // Print or use the attachment URL as needed

        System.debug('Attachment URL: ' + attachmentUrl);

    } else {

        // Handle case where there are no attachments

        System.debug('No attachments found.');

    }

     

    This code snippet assumes that your JSON string has been stored in the jsonString variable. It first deserializes the JSON string into a map, then extracts the attachments array from the map. It checks if the attachments array is not null and not empty. If there are attachments, it extracts the first attachment object and then extracts the attachment_url attribute from it. Finally, it prints or uses the attachment URL as needed.

     

    Hope this content will provide more understanding to you,

    Thanks!

0/9000

Check out my latest article: Do you want to call the Salesforce #Metadata API from Apex? 

You will see an example of calling the Metadata API through the MetadataService.cls, and how to keep the MetadataService.cls up to date.

0/9000
4 comments
  1. Feb 6, 2024, 4:39 PM

    @Gonzalo Gambino that is disapointing but what I expected. I feel like official/easier support of simply doing a REST API loopback callout to the untouched, existing REST API would be amazing. Even if it counts as a callout still. Basically just support reliable auth for doing so would be a huge improvement over today.

0/9000