Some time ago I've started to use Python with Pandas and Simple-Salesforce to make data migration to Salesforce orgs. I want to insert Account records and Contact records that have lookup to Account records. Instead of a Salesforce record ID of a related record, I want to use an external ID to associate/connect records. When I'm making this kind of insert operation for Contact records with Salesforce Inspector instead of using AccountId field I can use Account.ExternalId__c, with Data Loader it's Account:ExternalId__c.

What is a notation that should be used for simple-salesforce? When I'm using Account.ExternalId__c or Account:ExternalId__c I'm receiving this error:

simple_salesforce.exceptions.SalesforceMalformedRequest: Malformed request _https://xxx.my.salesforce.com/services/async/42.0/job/some_id/batch/some_id2/result. Response content: {'exceptionCode': 'InvalidBatch', 'exceptionMessage': 'Records not processed'}

I'm using this simple-salesforce method to insert records:

sf.bulk.Account.insert(data_json, batch_size=100, use_serial=False)

Of course when I'm trying to import related records by Data Loader or Salesforce Inspector everything is working fine, so I'm guessing that it's issue with notation in Simple-Salesforce.


1 Answer 1


Below solution and explanation if someone will looking for this in the future.

Previous version of my data_json:

data_json = {'FirstName': 'Test 1', 
             'LastName': 'Name 1', 
             'Email': '[email protected]', 
             'AccountId': 'someAccountId'}

I had to:

  • rename 'AccountId' key to 'Account'
  • create new dictionary: extIdDict = {'ExternalId__c': 'someExternalId'}
  • add extIdDict dictionary as a value to 'Account' key: row['Account'] = extIdDict

Finally, I have data_json like this:

data_json = {'FirstName': 'Test 1', 
             'LastName': 'Name 1', 
             'Email': '[email protected]', 
             'Account': {'ExternalId__c': 'someExternalId'}}

With this kind of json I was able to use it as a parameter in insert method mentioned in my original question and successfully insert contact records linked with account records.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .