Daily Archives: 05/17/2011

Upserting into SalesForce using .net and SOAP API

I’ve been experimenting with the classes created by Darren Terrell in the article “SalesForce integration with .net web services SOAP API” and found that there is a limit of 200 rows for upserts, so I’ve changed the Upsert() method as below to divide and submit the upserts in batches of 200 items at a time.

public UpsertResult[] Upsert(string externalID, sObject[] items)
{
   SetupService();
   // send in batches of 200 updates
   int iIndex = 0;
   List objResults = new List(items.Count());
   while (iIndex < items.Count())
   {
      sObject[] obj200Items = items.SubArray(iIndex, 200);
      objResults.AddRange( salesforceService.upsert(externalID, obj200Items) );
      iIndex += 200;
   }
   return objResults.ToArray();
 }

The SubArray method is defined as an extension below:

public static class ArrayExtensions
{
 /// <summary>
 /// Extracts a subarray of a given number of items (count) from an array starting from a given position (startIndex)
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="arr">Array from which to extract a subarray</param>
 /// <param name="startIndex">Position from where to obtain the array items</param>
 /// <param name="count">Number of items</param>
 /// <returns></returns>
 public static T[] SubArray(this T[] arr, int startIndex, int count)
 {
    var sub = new T[count];
    int iActualCount = count;
    if( arr.Count() - startIndex < count )
       iActualCount = arr.Count() - startIndex;
    Array.Copy(arr, startIndex, sub, 0, iActualCount);
    return sub;
 }
}
Advertisements

jQuery Visual Cheat Sheet

Very useful!

http://woorkup.com/wp-content/uploads/2011/05/jQuery-1.6-Visual-Cheat-Sheet.pdf

SalesForce integration with .Net

Darren Terrell has a series of very good articles about SalesForce and .Net integration:

SalesForce integration with .net web services SOAP API
How to make .net query/insert/upsert/update/delete SalesForce objects.

SalesForce Integration with .net custom web services
How to make .net consume a web service created in SalesForce.

SalesForce Integration with .net callouts
How to make SalesForce consume a SOAP/REST web service created in .net.