Created
April 4, 2019 01:12
-
-
Save dancinllama/100ddb04c22b322c0af44560f7e66d4a to your computer and use it in GitHub Desktop.
Revisions
-
James Loghry created this gist
Apr 4, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ //The enqueue deployment call (last call above), can optionally take a callback argument. //I was running into an issue and needed a bit more debugging, so here's my callback for that. //This call can be an inner class, by the way. public class CustomMetadataCallback implements Metadata.DeployCallback { public void handleResult(Metadata.DeployResult result, Metadata.DeployCallbackContext context) { System.debug('status: ' + result.status); if(!result.success){ System.debug('error1: ' + result.errorMessage); System.debug('error2: ' + result.errorStatusCode); System.debug('error3: ' + result.errorMessage); System.debug('error4: ' + result.numberComponentErrors); for(Metadata.DeployMessage msg : result.details.componentFailures){ System.debug('msg problem: ' + msg.problem); System.debug('msg problem type: ' + msg.problemType); } } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ Metadata.CustomMetadata settings = new Metadata.CustomMetadata(); settings.fullName = 'Your_Custom_Metadata_API_Name_WITHOUT_UNDERSCOREUNDERSCOREMDT_GOES_HERE.Default'; //Default is the name on 1 of many of my custom metadta type records settings.label = 'Default'; //Default is also a label. and you will need the label for the update to succeed. //Only updating one field.. if you need more fields updated, just instanciate more CustomMetdataValues and add them to the values list at line 9. Metadata.CustomMetadataValue dateValue = new Metadata.CustomMetadataValue(); dateValue.field = 'Current_Sales_Date__c'; //The field I'm updating dateValue.value = Date.newInstance(2019,3,8); //Value can be anything, really, but I needed a date. settings.values.add(dateValue); Metadata.DeployContainer mdContainer = new Metadata.DeployContainer(); mdContainer.addMetadata(settings); Metadata.Operations.enqueueDeployment(mdContainer, new CustomMetadataCallback());