1

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',
                      password='gonNur-gocgag-qenzi6',
                      security_token='6zZF84hnz4rCSYa7LxM0zVTQ')


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:
        disbursals.append(row)

    csv_iter = CsvDictsAdapter(iter(disbursals))
    batch = bulk.post_batch(job, csv_iter)
    print('Uploading...')
    bulk.wait_for_batch(job, batch)
    bulk.close_job(job)

    print("Done. Data Uploaded.")

enter image description here

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

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.

Update

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

12
  • 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.