I am trying to find an automated way to add contacts & leads to existing campaigns by using simple salesforce to upsert records to the CampaignMembers object. I have a CSV file with CampaignId and ContactId. However, I am getting an error that says "salesforce_bulk.salesforce_bulk.BulkBatchFailed: Batch 7514x000004NZJLAA4 of job 7504x000004QWlvAAG failed: InvalidBatch : Field name not found : CampaignId"

Here is a picture of the CSV file I am trying to upload. enter image description here

Is it even possible to add contacts and leads to campaigns in this manner?

Here is my code using the python lib 'salesforce-bulk':

import csv
from salesforce_bulk import SalesforceBulk
from salesforce_bulk import CsvDictsAdapter

bulk = SalesforceBulk(username='parth@killbusyseason.com',

def upsert(obj, file_location):

    job = bulk.create_upsert_job("{}".format(obj), contentType='CSV', external_id_name='Id')

    reader = csv.DictReader(open(r'{}'.format(file_location)))
    disbursals = []
    for row in reader:

    csv_iter = CsvDictsAdapter(iter(disbursals))
    batch = bulk.post_batch(job, csv_iter)
    bulk.wait_for_batch(job, batch)

    print("Done. Data Uploaded.")

enter image description here

  • Did you check Field Level Security?
    – Adrian Larson
    Jun 8 at 21:43
  • Yes. @AdrianLarson Jun 8 at 21:47

Make sure that you are Marketing User.

You can find Marketing User checkbox on the User record that you are using to load data. Campaign objects security depends on this permission.

When enabled and the user has Read permission on contacts or the Import permission on Leads, and Edit permission on campaigns, the user can create, edit, and delete campaigns, configure advanced campaign setup, and add campaign members and update their statuses with the Data Import Wizard.


Double verify all the permissions listed here are taken care of.

After an examination, the problem seems to be in the library salesforce-bulk. The library has not been updated in a while and seems like it causes this issue due to invalid headers sent as discussed here.

You can avoid it and use simple-salesforce

  • I have system admin access and here are my field-security settings for Campaign Member object (see new image above). It seems correct to me. @MohithShrivastava Jun 9 at 13:20
  • 2
    FLS is not the same thing as Marketing User. You need to check that setting on your User record.
    – David Reed
    Jun 9 at 13:24
  • Marketing User was already enabled for my User record. @DavidReed Jun 9 at 13:53
  • 2
    @ParthPatel Can you add the campaign member records manually via the UI? Also make sure you are using your org username for running the job! I was able to replicate and moment I use marketing user checkbox the issue was fixed! So double check Jun 9 at 13:57
  • 1
    I am using simple salesforce. I posted my code above @MohithShrivastava Jun 9 at 14:10

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.