I am trying to bulk load a csv file with 11000 records using Python with the simple-salesforce API.

The error that I am running into is that when I try to load the file, I get this message:

{'created': False,
  'errors': [{'fields': ['external_field__c'],
              'message': "Json Deserialization failed on token 'external_field__c' "
                         'and has left off in the middle of parsing a row. '
                         'Will go to end of row to begin parsing the next row',
              'statusCode': 'INVALID_FIELD'}]

I am able to load just one record using my code, but anything greater than 1 then I get the JSON Deserialization error. I have validated that the API name in the Object Manager is the same as what I am trying to upload.

This is my code:

from simple_salesforce import Salesforce
from pprint import pprint
import json
import pandas as pd
from pandas import json_normalize
from sfbulk2 import SFBulk2
import requests
import csv
from salesforce_bulk import CsvDictsAdapter

load_data = pd.read_csv('C:\\Users\\BlahBlah\\Desktop\\test_csv4.csv')   
load_data = load_data.fillna('')
bulk_data = []
for row in load_data.itertuples():
    d = row._asdict()
    del d['Index']

sf = Salesforce(username='username', password='password', security_token='token', domain='test')    
x = sf.bulk.Account.upsert(bulk_data,batch_size=10000, external_id_field='external_field__c')

I am thinking that there might be something very simple I could be missing with this code, but I have tried to research this issue for hours without getting anywhere.

Edit Adding "fake" data:

9999,SMITH,JOHN,,1970-01-01,XXXXXXXXXXXXXXX,99999999999,123 ANY STREET,ANYTOWN,NY,10001,USA```

  • SFDMU does this out of the box
    – identigral
    Commented Nov 15, 2022 at 23:23
  • could you add the file you are trying to upload? I mean the one which works and the other which doesn't work? Commented Nov 16, 2022 at 0:17
  • @identigral Unfortunately this will not work for me since I need to be able to extract data from a DB to transfer in to Salesforce on a scheduled basis. I wish that this could work for me.
    – Perdue
    Commented Nov 16, 2022 at 14:51
  • @EliveltonWalter Basically the data where one record uploads has the header and one record to it. The other one has about 10 records in it with the header row. Both files are comma delimited. I cannot add the file due to confidentiality reasons, but it's basically a simple demographics file with things like Name, Address, Internal Id Number, etc.
    – Perdue
    Commented Nov 16, 2022 at 14:52
  • @Perdue Your question is about loading from CSV. SFDMU does this.
    – identigral
    Commented Nov 16, 2022 at 15:26


You must log in to answer this question.

Browse other questions tagged .