Skip to content

Instantly share code, notes, and snippets.

@tugce
Created May 26, 2020 15:32
Show Gist options
  • Save tugce/51db700d921367744ee37dd25cba39e4 to your computer and use it in GitHub Desktop.
Save tugce/51db700d921367744ee37dd25cba39e4 to your computer and use it in GitHub Desktop.
Apex script to create one metadata group called All Metadata with all metadata types
copado__Metadata_Group__c allMetadata = new copado__Metadata_Group__c ();
allMetadata.Name = 'All Metadata Types';
insert allMetadata;
List<copado__Metadata_Group_Item__c> items = new List<copado__Metadata_Group_Item__c>();
Schema.DescribeFieldResult typeResult = copado__Metadata_Group_Item__c.copado__Type__c.getDescribe();
List<Schema.PicklistEntry> ple = typeResult.getPicklistValues();
for( Schema.PicklistEntry f : ple) {
copado__Metadata_Group_Item__c item = new copado__Metadata_Group_Item__c();
item.copado__Type__c = f.getValue();
item.copado__Metadata_Group__c = allMetadata.Id;
item.copado__Operator__c = 'All';
items.add(item);
}
insert items;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment