Tag Archives: Bulk API

SFBulkAPIStarter: Attachment Support Added

SFBulkAPIStarter Overview

A couple years ago I was enhancing an ETL tool at work to add Salesforce Bulk API support so our data migration projects would execute faster. To help others understand how to use the Salesforce Bulk API, the SFBulkAPIStarter open source project was started.

It’s a C# library that has starter code demonstrating how to use the Salesforce Bulk API. The test project has test classes demonstrating how to do various Bulk API  tasks such as inserting, upserting, querying, and deleting records.

To take it for a spin, download it from Nuget.

Attachment Support Added

It’s been a while since I had contributed to the SFBulkAPIStarter project so I added support for adding an attachment to a specified record.

Attachment High-Level Steps

The steps to add an attachment to a Salesforce record were easier than expected:

  1. Create an Insert Attachment Bulk Job.
  2. Create a request.txt file containing one or more records with the following fields
    • Name – Name of the attachment to show in Salesforce.
    • Body – The “#” prefixed path of the file in the zip file.
    • ParentId – The Id of the Salesforce record to attach the attachment to.
  3. Create a zip file with the request.txt file and the file(s) to attach.
  4. Create a batch in the job whose request file is the zip file.

Attachment Code

Here’s the attachment method in the BulkAPIClient class that handles the attachment logic. Currently, this method handles attaching one attachment and not multiple.

Test Code

Here’s the test from the TestBulkApiClient class that attaches a file to a specified Salesforce record.

How often do you use the Bulk API? How about attaching an attachment to a record?

Happy Coding,


Salesforce Bulk API Starter Nuget Installation Issue

danieleboldrini reported the following issue when trying to install the SFBulkAPIStarter Nuget package in VisualStudio 2015. Full Issue Details

Could not install package ‘SFBulkAPIStarter 0.12.0’. You are trying to install this package into a project that targets

‘.NETFramework,Version=v4.5.2’, but the package does not contain any assembly references or content files that are compatible with that framework.

With VisualStudio 2015 Community, I was able to reproduce the issue in a new console application. Doing the same in VisualStudio 2013 Community installed fine. Very weird.

After digging around a bit, Microsoft changed how they treat Nuget package lib contents in VisualStudio 2015. In version 0.12, all the DLLs were under the lib folder because they weren’t targeting any specific version of the .NET runtime since there wasn’t a specific version dependency.

To appease the VisualStudio 2015 gods, the DLLs were put under the net45 folder in the Libs folder and released in version 0.13 on Nuget.

What Nuget packaging issues have you encountered? Is there a better way to handle this?