Created
January 29, 2020 19:18
-
-
Save dhaniksahni/29a61d8747197890b8cb5b77d2b8f868 to your computer and use it in GitHub Desktop.
This file contains 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 characters
public class MetadataService { | |
public static void UpdateCustomMetadata(string token) { | |
Metadata.CustomMetadata customMetadata = new Metadata.CustomMetadata(); | |
customMetadata.fullName = 'GoogleAuthSetting.AccessToken'; | |
customMetadata.label = 'AccessToken'; | |
customMetadata.protected_x = true; | |
Metadata.CustomMetadataValue accessToken = new Metadata.CustomMetadataValue(); | |
accessToken.field = 'AccessToken__c'; | |
accessToken.value = token; | |
customMetadata.values.add(accessToken); | |
Metadata.DeployContainer mdContainer = new Metadata.DeployContainer(); | |
mdContainer.addMetadata(customMetadata); | |
CustomMetadataCallback callback = new CustomMetadataCallback(); | |
Id jobId = Metadata.Operations.enqueueDeployment(mdContainer, callback); | |
} | |
public class CustomMetadataCallback implements Metadata.DeployCallback { | |
public void handleResult(Metadata.DeployResult result, | |
Metadata.DeployCallbackContext context) { | |
if (result.status == Metadata.DeployStatus.Succeeded) { | |
System.debug(' success : '+ result); | |
} else { | |
System.debug(' fail : '+ result); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment