Empty value issue
My CSV file looks like
DeveloperName,Level__c,Containing_Node_Label__c,Type__c,FieldA__c,FieldB__c,FieldC__c
OpportunityStage,0,,Field,,StageName,
Contacts,0,,List,Contacts_In_Opportunity__r,,
When I try upload, I'm getting this error:
Error occured processing component <CUSTOM_METADATA_TYPE_NAME>.OpportunityStage. Type: bad value for restricted picklist field: StageName (INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST). Fields Type__c.
It seems, that the tool skips empty values: ,, and ,
So, the issue is the way APEX .split() works.
'a,b,c'.split(',') => (a,b,c)
'a,b,'.split(',') => (a,b)
'a,,'.split(',') => (a)
and so on...
It may be solved with regex...
This is machine translation sentences.
@michacom hi I think splitting the header row and the data row separately and resolving it by taking the number of elements of the header row as an argument.
- Split the header line and count the number of elements
- Specify the number of elements as split and the minus value as the second argument.
- You can get results without missing. I did it! ! And this is an ancient technique in Java
'head_col_1,head_col_3,head_col_3'.split(',').length()=>3
'a,,'.split(',',-3) => (a, , )
Workaround until the solution is fixed:
My csv was like
Label,Field_A__c,Field_B__c,Field_C__c
Field_C__c had some empty values, so I ended up making 2 different csv files one with Field_C__c and one without. worked for me
I've proposed a simple fix here, which works for me. Interested to hear if it breaks anything else?
https://github.com/forcedotcom/CustomMetadataLoader/commit/1a6c01a51c462ec3b67f3d5ff5f7e3aa74a62e73
Duplicate of https://github.com/forcedotcom/CustomMetadataLoader/issues/9