Skip to content

Instantly share code, notes, and snippets.

@Sunil02kumar
Last active July 8, 2018 06:33
Show Gist options
  • Save Sunil02kumar/b3ee2b5f1e63b65de9038aeb71a3c0d2 to your computer and use it in GitHub Desktop.
Save Sunil02kumar/b3ee2b5f1e63b65de9038aeb71a3c0d2 to your computer and use it in GitHub Desktop.
//Author- sunil Kumar
//@sunil02kumar
// skforce is namespace of my org.
public class MetadataAPICMUtility{
public static boolean createCustomMetadata(){
List<MetadataService.Metadata> allMetadataList = new List<MetadataService.Metadata>();
MetadataService.MetadataPort service = createService();
MetaDataService.CustomMetadata CMTRec = new MetaDataService.CustomMetadata();
//fullname refer custom metadata name.unique name
CMTRec.fullName = 'skforce__Configuration_Settings.ConfSetting1';
CMTRec.description = 'Store Configuration settings';
CMTRec.label = 'Configuration_settings1';
CMTRec.protected_x = false;
//now specify field values
List<MetaDataService.CustomMetadataValue> CMFieldValues = new List<MetaDataService.CustomMetadataValue>();
MetaDataService.CustomMetadataValue field1= new MetaDataService.CustomMetadataValue();
field1.field='skforce__Help_Url__c';
field1.value= 'https://www.sfdcstuff.com/search/label/Lightning';
CMFieldValues.add(field1);
MetaDataService.CustomMetadataValue field2= new MetaDataService.CustomMetadataValue();
field2.field='skforce__Home_Page_URL__c';
field2.value= 'https://www.sfdcstuff.com/search/label/Lightning';
CMFieldValues.add(field2);
CMTRec.values = CMFieldValues;
allMetadataList.add(CMTRec);
system.debug('*******allMetadataList:'+allMetadataList);
List<MetadataService.SaveResult> results = service.createMetadata(allMetadataList);
for(MetadataService.SaveResult result: results){
system.debug('create custo metadata results success='+result.success);
}
return results[0].success;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment