What it should be doing is switch our UAT sandboxes endpoint to point to our UAT server on refresh, or void the transaction key in any other sandbox, causing any requests to be rejected outright.So, the question is, what am I missing? Can you intentionally not do a metadata deployment out of a SandboxPostCopy script? I can think of some other workarounds, such as having additional metadata records and extra logic in my code to grab a different record depending on the instance, but i'd rather introduce as little uneeded complexity as I can. I could also revert to using custom settings instead, but that seems like a step backwards to something that is largely inferior in 'most' situations.Thanks!-BrianMetadata.CustomMetadata ecasConnection = new Metadata.CustomMetadata();
ecasConnection.fullName = 'Connection_Setting__mdt.ECAS';
ecasConnection.label = 'ECAS';
if (context.sandboxName().equalsIgnoreCase('UATFull'))
{
Metadata.CustomMetadataValue endpointRoot = new Metadata.CustomMetadataValue();
endpointRoot.field = 'Endpoint_Root__c';
endpointRoot.value = '.../ECAS/salesforce';
ecasConnection.values.add(endpointRoot);
}
else
{
Metadata.CustomMetadataValue transactionKey = new Metadata.CustomMetadataValue();
transactionKey.field = 'Transaction_Key__c';
transactionKey.value = 'void';
ecasConnection.values.add(transactionKey);
}
Metadata.DeployContainer metadataContainer = new Metadata.DeployContainer();
metadataContainer.addMetadata(ecasConnection);
if (!Test.isRunningTest())
Metadata.Operations.enqueueDeployment(metadataContainer, null);
I posted a relevant discussion on the Apex Metadata API success group and it looks like what we are looking to do (updating custom metadata setting records via the the SandboxPostCopy Interface) is possible via the Apex Metadata API.
Here's a link to the relevant discussion:
https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007epyWrSAI