Skip to content

Commit 131de83

Browse files
authored
CustomMetadataSaver now uses an inner class, FlowInput, for Flow parameters (#8)
1 parent a3bd910 commit 131de83

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

force-app/main/custom-metadata-saver/classes/CustomMetadataSaver.cls

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
//----------------------------------------------------------------------------------------------------//
55

66
public inherited sharing class CustomMetadataSaver {
7-
private static final Set<String> IGNORED_FIELD_NAMES = getIgnoredFieldNames();
87
private static final List<String> DEPLOYMENT_JOB_IDS = new List<String>();
8+
private static final Set<String> IGNORED_FIELD_NAMES = getIgnoredFieldNames();
9+
10+
public class FlowInput {
11+
@InvocableVariable(required=true label='The collection of custom metadata type records to deploy')
12+
public List<SObject> customMetadataRecords;
13+
}
914

1015
private CustomMetadataSaver() {
1116
//static only
@@ -16,12 +21,12 @@ public inherited sharing class CustomMetadataSaver {
1621
label='Deploy Changes to Custom Metadata Records'
1722
description='Deploys changes to the list of custom metadata records'
1823
)
19-
public static void deploy(List<List<SObject>> customMetadataRecordsLists) {
20-
System.debug('customMetadataRecordsLists==' + customMetadataRecordsLists);
24+
public static void deploy(List<FlowInput> inputs) {
25+
System.debug('inputs==' + inputs);
2126

2227
List<SObject> consolidatedList = new List<SObject>();
23-
for (List<SObject> customMetadataRecordsList : customMetadataRecordsLists) {
24-
consolidatedList.addAll(customMetadataRecordsList);
28+
for (FlowInput input : inputs) {
29+
consolidatedList.addAll(input.customMetadataRecords);
2530
}
2631

2732
System.debug('consolidatedList==' + consolidatedList);

force-app/tests/custom-metadata-saver/classes/CustomMetadataSaver_Tests.cls

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@isTest
77
private class CustomMetadataSaver_Tests {
88
@isTest
9-
static void it_should_deploy_cmdt_record() {
9+
static void it_should_deploy_cmdt_record_for_list_of_cmdt() {
1010
CustomMetadataDeployTest__mdt cmdtRecord = new CustomMetadataDeployTest__mdt(
1111
MasterLabel = 'my test cmdt record',
1212
DeveloperName = 'my_test_cmdt_record',
@@ -26,4 +26,31 @@ private class CustomMetadataSaver_Tests {
2626

2727
System.assertEquals(1, CustomMetadataSaver.getDeploymentJobIds().size());
2828
}
29+
30+
@isTest
31+
static void it_should_deploy_cmdt_record_for_list_of_flowInputs() {
32+
CustomMetadataDeployTest__mdt cmdtRecord = new CustomMetadataDeployTest__mdt(
33+
MasterLabel = 'my test cmdt record',
34+
DeveloperName = 'my_test_cmdt_record',
35+
ExampleCheckboxField__c = true,
36+
ExampleDateField__c = System.today(),
37+
ExampleDatetimeField__c = System.now(),
38+
ExampleTextField__c = 'hello'
39+
);
40+
41+
List<CustomMetadataDeployTest__mdt> cdmtRecords = new List<CustomMetadataDeployTest__mdt>{ cmdtRecord };
42+
CustomMetadataSaver.FlowInput input = new CustomMetadataSaver.FlowInput();
43+
input.customMetadataRecords = cdmtRecords;
44+
45+
List<CustomMetadataSaver.FlowInput> inputs = new List<CustomMetadataSaver.FlowInput>();
46+
inputs.add(input);
47+
48+
System.assertEquals(1, cdmtRecords.size());
49+
50+
Test.startTest();
51+
CustomMetadataSaver.deploy(cdmtRecords);
52+
Test.stopTest();
53+
54+
System.assertEquals(1, CustomMetadataSaver.getDeploymentJobIds().size());
55+
}
2956
}

0 commit comments

Comments
 (0)