0

I have one excel with SFDC label Name, as a header and their corresponding records, and using lightning component I need to Create record from that.

My Approach : I am taking the input in apex from js controller in json form [{"Supplier Invoice Number":"14489","Amount(Gross)":"999.99","Description":"App","Status":"Downloaded"}, ...] and deserialized using untyped after which i used Schema.SObjectField to get the field API, label and datatype and then using further to iterate over excel header and adding the values in a map to insert.

My Blocker : In future there could be a possibility that label could be duplicate or any extra fields get added on, then in apex code we need to update a logic, so i want to reduce the effort at code level as much as possible after any change in field datatype or add on field in excel.

My Query : So shall i go with custom metadata by creating the two fields as Field API and Field Label and user will manually map the excel field with Metadata and i will be using from here or shall i go with my previous approach.

Thanks Pranav

2
  • What have you tried so far and where are you facing issue? Aug 27 '19 at 5:29
  • @salesforce-sas Mentioned... Aug 27 '19 at 6:03
2

You should not really depend on labels directly for creating records.

options are as below:

  1. You can have a separate CSV which has mapping from label to API name. You can provide this file to user so that he does not create duplicate labels .
  2. Either use field API names instead of labels in CSV in top row Or else API names can be put in 1st row (index 1) through which you can identify correct fields which processing in apex .
  3. You can maintain custom settings/custom metadata-types for mapping of labels/APIs.

In my experience, it is good to give some responsibility to users to maintain data integrity. i.e., 1st option or 2nd option. In this case, Users become aware of the repercussions they may face if they dont give correct labels/API names. But here, you need to make sure that initially you take a small training session on how to prepare CSV file for upload.

1
  • I agree that one should not depend on labels directly for creating records. But if we think from user end the api name could be appropriate for them,that is the reason i planned to go with exact field label in excel 1st header column but later on realized that it is getting complicated and might create issue in future if there is any update in excel column or data type change in existing field. So i was planning to go with custom meta data by using Metadata Relationship. Aug 27 '19 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.