Preparing package.xml for custom metadata records and sending email containing it to the current user

Preparing package.xml for custom metadata records and sending email containing it to the current user


public class MD {
public static String buildPackageXMLForMD(SObjectType mdt, String whereClause){
String mdtName = [ select DeveloperName FROM EntityDefinition where QualifiedAPIName = :mdt.getDescribe().getName() ].DeveloperName;

List records = Database.query(‘SELECT DeveloperName FROM ‘ + mdt + whereClause );
List items = new List();
for (SObject r: records) {
items.add( mdtName + ‘.’ + r.get( ‘DeveloperName’ ) );
}
return ‘ \r\n ‘ + String.join( items, ‘\r\n ‘ ) + ‘\r\n CustomMetadata\r\n ‘;
}

public static void sendPackageXMLEmail(String attachmentContent) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new List{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[]{
mail
});
}
}

and

MD.sendPackageXMLEmail(MD.buildPackageXMLForMD(Custom_Metadata__mdt.sObjectType,
‘ where Parent_Metadata__r.DeveloperName = \’Parent_Dev_Name\”));

Advertisements
This entry was posted in salesforce. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s