2

I am trying to load some (FinServ__ReciprocalRole__c) data using dataLaoder. This data should be imported to many environments (sandboxes and scratch orgs). Given that the RecordType ID is not the same in the various sandboxes and sratch orgs, i want to use the RecordType name instead of the ID as it's consistent across all environments.

Here is an example of a record that i am trying to import:

FinServ__CreateInverseRole__c, Name,   FinServ__InverseRole__c, RecordType.Name
"FALSE",                       "TEST", "INVERSE TEST",          "Contact Role"

No data was imported and i a got this error message:

RecordType ID: id value of incorrect type: Contact Role

Note: I've already checked the accessibility of the record types in my profile.

Did any one encounter this kind of issue by any chance ? thanks for your help.

  • Did you enable Bulk API mode? – sfdcfox Feb 12 at 16:16
  • @sfdcfox No, i did not enable Bulk API – Merabti Ibrahim Feb 12 at 16:18
  • Try using the Bulk API mode in settings... – sfdcfox Feb 12 at 16:36
  • with the same file ? ,i mean with this "RecordType.Name" as a header ? – Merabti Ibrahim Feb 12 at 16:38
  • Yes, the Bulk API mode should support that syntax. – sfdcfox Feb 12 at 17:12
3

FRAME CHALLENGE

For one-time imports from a CLI to use in multiple orgs (including scratch orgs), you should be using sfdx. This allows you to write a shell script/batch file that allows you to make a portable upload:

sfdx force:data:bulk:upsert -s FinServ__ReciprocalRole__c -f file/to/import.csv -i Id -w 10

Using the Bulk API allows you to specify references, as outlined in Relationship Fields in a Header Row.

The Data Loader is not purpose-built for migrating data between orgs (thus manual mapping in Excel/external apps is often required), so it lacks many of the features that are found in SFDX and newer tools.

  • Yep, this works. Didn't think it this way. But I will still think as long as its a data load activity, and that you need to utilize say data loader, still stick with RecordTypeId to reduce any complexity. – Jayant Das Feb 12 at 18:39
  • I keep getting this error message "DUPLICATE_EXTERNAL_ID:Name: more than one record found for external id field" when i try to execute the command line above. i have no data in my scratch so, it's kind of strange to have this error. I noticed though that when get rid of "RecordType.Name" column , it works and this errors disappears. SO, if this worked for you ,i must have missed something – Merabti Ibrahim Feb 13 at 13:55
  • 1
    @MerabtiIbrahim Name needs to be unique. For example, if you have two record types named "Household" on two separate objects, this could cause this error. You'll need to have unique record type names for this to work. – sfdcfox Feb 13 at 14:17
  • @sfdcfox,so you want to say that there is another record type with the same name on another object ? – Merabti Ibrahim Feb 13 at 14:21
  • 1
    @MerabtiIbrahim That's the usual case, yes. I don't know why it does this, but that's how it behaves. – sfdcfox Feb 13 at 14:28
2

I know one way you can use. You have to use a custom field and a trigger.

  1. Create a text field on FinServ__ReciprocalRole__c named as RecordTypeTemp__c
  2. Write a before insert trigger on FinServ__ReciprocalRole__c to map RecordTypeTemp__c into RecordType Id

    Trigger ReciprocalRoleTrigger on FinServ__ReciprocalRole__c (before insert){
    
        Map<String , Schema.RecordTypeInfo> reciprocalNameRecordTypeMap = FinServ__ReciprocalRole__c.SObjectType.getDescribe().recordTypeInfosByDeveloperName;
    
    
        for(FinServ__ReciprocalRole__c ind : Trigger.new){
            ind.RecordTypeId = reciprocalNameRecordTypeMap.get(ind.RecordTypeTemp__c).recordTypeId;
        }
    }
    

Now when you load data, dont populate recordTypeId field just populate RecordTypeTemp__c with the developer name to make a consistent behaviour in dataload accross all orgs

  • 1
    This will definitely work, but personally I wouldn't recommend building any customization to address a data loading activity. – Jayant Das Feb 12 at 15:52
  • 1
    @JayantDas I second that.4 – Pranay Jaiswal Feb 12 at 15:53
1

You cannot use Record Type Name in data loader to map to a particular record type. You will need to use RecordTypeId for this purpose.

As a reference, it is mentioned in this knowledge article:

Changing record types for multiple records via the dataloader is not as straight forward as it would seem. Instead of using the record type name, usage of the record type ID gathered via the URL is required.

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.