Scenario:
You might have used the "Custom Metadata Loader" to perform the bulk insert and bulk update. Sometimes it's might be required to perform the bulk delete also ,but unfortunately this tool doesn't support as of today.
Solution:
So as a workaround we can have apex code snippet which can be used to perform the bulk deletion(in a single run max 200 records) of metadata .Please use the below code snippet for the same.
Source Code:
MetadataService.MetadataPort service = new MetadataService.MetadataPort();
// Set the session id
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();
//Add all your metadata records developer name to list
List<String> recordsToDelete = new List<String>();
For(YourMedataDataName__mdt m :[SELECT Developername from YourMedataDataName__mdt Limit 200])
{
String s = 'YourMedataDataName__mdt.'+m.Developername;
recordsToDelete.add(s);
}
//Perform the bulk deletion at a time max of 200 records
MetadataService.DeleteResult [] results = new MetadataService.DeleteResult []{};
results = service.deleteMetadata('CustomMetadata', recordsToDelete);
Please comment or write us if you have any queries/requirements.
Please like,follow,bookmark,subscribe this site to receive daily updates.
LinkedIn Group - Srinivas4sfdc (I Love Coding... You?)
FaceBook Page - I Love Coding. You?
Please comment or write us if you have any queries/requirements.
Please like,follow,bookmark,subscribe this site to receive daily updates.
LinkedIn Group - Srinivas4sfdc (I Love Coding... You?)
FaceBook Page - I Love Coding. You?
i get the error : Invalid type: MetadataService.MetadataPort
ReplyDeletePlease deploy this to salesforce instance.
Deletehttps://github.com/financialforcedev/apex-mdapi/blob/master/README.markdown
same issue. code doesnt work
ReplyDelete