Skip to content

Commit a3bd910

Browse files
authored
Fixed picklist deployment error (#6)
* Added extra if/else statement to explicitly cast picklists to strings * Removed redundant call for getPopulatedFieldsAsMap()
1 parent ddb39e7 commit a3bd910

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,19 @@ public inherited sharing class CustomMetadataSaver {
6666
continue;
6767
}
6868

69+
Schema.SObjectField field = customMetadataRecord.getSObjectType().getDescribe().fields.getMap().get(fieldName);
70+
71+
Object value;
72+
// Picklist values have to be cast to strings (even though they already look like strings)
73+
if (field.getDescribe().getType() == Schema.DisplayType.PICKLIST) {
74+
value = String.valueOf(customMetadataRecord.get(field));
75+
} else {
76+
value = customMetadataRecord.get(fieldName);
77+
}
78+
6979
Metadata.CustomMetadataValue customField = new Metadata.CustomMetadataValue();
7080
customField.field = fieldName;
71-
customField.value = customMetadataRecord.getPopulatedFieldsAsMap().get(fieldName);
81+
customField.value = value;
7282
System.debug(LoggingLevel.INFO, 'customField==' + customField);
7383

7484
customMetadata.values.add(customField);

0 commit comments

Comments
 (0)