1

I'm using the Salesforce .NET API to perform upserts of my data. So far I have been doing this by retrieving records I wish to upsert from a SQL backend and then upserting them one at a time.

This works fine as I can run it overnight as speed is not an issue. The problem is with hitting my TotalRequests limit.

Is it possible to use the .NET API and upsert multiple (say 200 records) at a time?

The UpdateExternalAsync method appears just to take an object rather than an array of objects. I can't see anything in the API to suggest a bulk upload?

Any help, greatly appreciated

A snippet of my code:-

foreach (DataRow row in dt.Rows)
{
    c = new Contact();

    c.Unique_Contact_ID__c = row["Unique_Contact_ID__c"].ToString();
    c.Account.Account_Unique_ID__c = row["Account_unique_id__c"].ToString();

    // other properties.....

     log.LogMessage(string.Format("Performing an Upsert for Contact {0}", c.Account.Account_Unique_ID__c));
     var response = await client.UpsertExternalAsync("Contact", "Unique_Contact_ID__c", c.Account.Account_Unique_ID__c, c);

     if (response.Success == "true")
     {
         log.LogMessage("Upsert successful");
     }
     else
     {
         log.LogMessage(string.Format("Upsert not successful for Contact {0}", c.Account.Account_Unique_ID__c));
     }

}
3

The Salesforce .NET Toolkit is a wrapper around salesforce standard REST API.

Up until recently the Standard Salesforce REST API was only supporting single record actions per call and I believe that's why the Toolkit had only methods with single record.

But with recent releases, Salesforce started supporting multiple records (composite resources) in REST api call (its called batch & tree modes and its now Generally available from version 34.0) , but the Toolkit might not have been updated to start using the new feature.

if you open up the toolkit method for UpsertExternalAsync, all it does is an HttpPatch to the standard rest endpoint

    public Task<SuccessResponse> UpsertExternalAsync(string objectName, string externalFieldName, string externalId, object record)
    {
        if (string.IsNullOrEmpty(objectName)) throw new ArgumentNullException("objectName");
        if (string.IsNullOrEmpty(externalFieldName)) throw new ArgumentNullException("externalFieldName");
        if (string.IsNullOrEmpty(externalId)) throw new ArgumentNullException("externalId");
        if (record == null) throw new ArgumentNullException("record");

        return _serviceHttpClient.HttpPatchAsync(record, string.Format("sobjects/{0}/{1}/{2}", objectName, externalFieldName, externalId));
    }

you can try few options if you want to pass multiple records in one go..

  1. start making your own Http calls with the .NET Http libraries and pass the required batchrequest JSON (The .NET HttpClient supports async methods for most of the calls)

  2. switch to standard salesforce soap api, and you get upsert methods taking an array of sobjects . check this reference for sample java and c# code

| improve this answer | |
  • Ok, I'll check those options out and report back. Thanks – David Jan 11 '16 at 11:24

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.