Created
October 30, 2018 14:55
-
-
Save Patlatus/906ec126e996bc19f4a52691060bce30 to your computer and use it in GitHub Desktop.
Build package.xml for Metadata Records
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 MD { | |
public static String buildPackageXMLForMD(SObjectType mdt, String whereClause){ | |
String mdtName = [ select DeveloperName FROM EntityDefinition where QualifiedAPIName = :mdt.getDescribe().getName() ].DeveloperName; | |
List<SObject> records = Database.query('SELECT DeveloperName FROM ' + mdt + whereClause ); | |
List<String> items = new List<String>(); | |
for (SObject r: records) { | |
items.add( mdtName + '.' + r.get( 'DeveloperName' ) ); | |
} | |
return ' <types>\r\n <members>' + String.join( items, '</members>\r\n <members>' ) + '</members>\r\n <name>CustomMetadata</name>\r\n </types>'; | |
} | |
public static void sendPackageXMLEmail(String attachmentContent) { | |
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); | |
mail.setToAddresses(new List<String>{UserInfo.getUserId()}); | |
mail.setSubject('Package.xml prepared'); | |
mail.setHtmlBody(''); | |
if (attachmentContent != null) { | |
Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment(); | |
attachment.setFileName('package.xml'); | |
attachment.setBody(Blob.valueOf( attachmentContent)); | |
mail.setFileAttachments(new Messaging.EmailFileAttachment[]{ | |
attachment | |
}); | |
} | |
Messaging.sendEmail(new Messaging.SingleEmailMessage[]{ | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment