forcedotcom / SFDX-Data-Move-Utility

SFDMU is a cutting-edge Salesforce data migration tool for seamless org population from other orgs or CSV files. It handles all CRUD operations on multiple related objects in one go.
BSD 3-Clause "New" or "Revised" License
444 stars 74 forks source link

[FEATURE REQUEST]- Support FieldMapping when using sourceusername csvfile #627

Closed IamDrowsy closed 1 year ago

IamDrowsy commented 1 year ago

We would like to upload data from csv files to Salesforce that come from different sources. But the columns of those files do not match fields in Salesforce. We could rename the columns to match the fields, but it would be nice when FieldMapping could be used to solve this with sfdmu only. (The documentation does not state if FieldMapping is supported with csv import, but we tried it and it does not seem to work).

Example Given the following 'Account.csv' and 'export.json', it would be nice if sfdmu would upsert an Account with Name='MyAccount' and External_Id__c='X1234'.

Account_Name Account_Id
MyAccount X1234
{
    "objects": [
        {
            "query": "SELECT Account_Name,Account_Id FROM Account",
            "operation": "Upsert",
            "externalId": "Account_Id",
            "useFieldMapping": true,
            "fieldMapping": [
                {
                    "targetObject": "Account"
                },
                {
                    "sourceField": "Account_Name",
                    "targetField": "Name"
                },
                {
                    "sourceField": "Account_Id",
                    "targetField": "External_Id__c"
                }
            ]
        }
    ]
}
hknokh2 commented 1 year ago

Hello,

Thank you for reaching out and providing such a detailed example. I fully recognize the potential advantages that field mapping could offer when uploading data from various CSV sources directly to Salesforce using sfdmu. However, since CSV columns and files can easily be renamed to align with Salesforce fields, the immediate need for this feature might be less pressing.

While the idea of having a field mapping feature for CSV sources is undoubtedly appealing, it seems that this feature can be postponed for now. I will keep this on my list for future consideration and will certainly keep you updated on any progress.

Best Regards.

hknokh commented 1 year ago

Hello, I hope the issue has been resolved for you. I'm closing it for now. Please let me know if you have any further questions. Regards.

IamDrowsy commented 1 year ago

Hello,

thank you very much for your response and putting this on the roadmap. I totally agree that the workaround is very easy and this should not have a high priority.

As a side note, I just wanted to mention that you currently can use the FieldMapping to import from csv files that are named differently (and even with multiple files). So two files, MainAccounts.csv, OtherAccounts.csv with the correct columns can be imported with the following export.json:

{
    "objects": [
        {
            "query": "SELECT Name,External_Id__c FROM MainAccounts",
            "operation": "Upsert",
            "externalId": "External_Id__c",
            "useFieldMapping": true,
            "fieldMapping": [
                {
                    "targetObject": "Account"
                }
            ]
        },
        {
            "query": "SELECT Name,External_Id__c FROM OtherAccounts",
            "operation": "Upsert",
            "externalId": "External_Id__c",
            "useFieldMapping": true,
            "fieldMapping": [
                {
                    "targetObject": "Account"
                }
            ]
        }
    ]
}

Not sure if this is intentional and should/could be mentioned in the docs, but I found it interesting.

Thanks again for your efforts and sfdmu as a whole. Regards.