{"id":53,"date":"2011-05-17T22:03:29","date_gmt":"2011-05-17T17:03:29","guid":{"rendered":"http:\/\/learnsf.wordpress.com\/?p=53"},"modified":"2011-05-17T22:03:29","modified_gmt":"2011-05-17T17:03:29","slug":"upserting-into-salesforce-using-net-and-soap-api","status":"publish","type":"post","link":"https:\/\/blog.felineflock.com\/index.php\/2011\/05\/17\/upserting-into-salesforce-using-net-and-soap-api\/","title":{"rendered":"Upserting into SalesForce using .net and SOAP API"},"content":{"rendered":"<p>I&#8217;ve been experimenting with the classes created by <a href=\"http:\/\/www.developer.com\/author\/Darren-Terrell-117870.htm\">Darren Terrell<\/a> in the article &#8220;<a href=\"http:\/\/www.developer.com\/net\/net\/salesforce-integration-with-.net-web-services-soap-api-.html\">SalesForce integration with .net web services SOAP API<\/a>&#8221; and found that there is a limit of 200 rows for upserts, so I&#8217;ve changed the Upsert() method as below to divide and submit the upserts in batches of 200 items at a time.<\/p>\n<pre>public UpsertResult[] Upsert(string externalID, sObject[] items)\n{\n   SetupService();\n   \/\/ send in batches of 200 updates\n   int iIndex = 0;\n   List objResults = new List(items.Count());\n   while (iIndex &lt; items.Count())\n   {\n      sObject[] obj200Items = items.SubArray(iIndex, 200);\n      objResults.AddRange( salesforceService.upsert(externalID, obj200Items) );\n      iIndex += 200;\n   }\n   return objResults.ToArray();\n }<\/pre>\n<p>The SubArray method is defined as an extension below:<\/p>\n<pre style=\"padding-left:30px;\">public static class ArrayExtensions\n{\n \/\/\/ &lt;summary&gt;\n \/\/\/ Extracts a subarray of a given number of items (count) from an array starting from a given position (startIndex)\n \/\/\/ &lt;\/summary&gt;\n \/\/\/ &lt;typeparam&nbsp;name=\"T\"&gt;&lt;\/typeparam&gt;\n \/\/\/ &lt;param&nbsp;name=\"arr\"&gt;Array from which to extract a subarray&lt;\/param&gt;\n \/\/\/ &lt;param&nbsp;name=\"startIndex\"&gt;Position from where to obtain the array items&lt;\/param&gt;\n \/\/\/ &lt;param&nbsp;name=\"count\"&gt;Number of items&lt;\/param&gt;\n \/\/\/ &lt;returns&gt;&lt;\/returns&gt;\n public static T[] SubArray(this T[] arr, int startIndex, int count)\n {\n    var sub = new T[count];\n    int iActualCount = count;\n    if( arr.Count() - startIndex &lt; count )\n       iActualCount = arr.Count() - startIndex;\n    Array.Copy(arr, startIndex, sub, 0, iActualCount);\n    return sub;\n }\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been experimenting with the classes created by Darren Terrell in the article &#8220;SalesForce integration with .net web services SOAP API&#8221; and found that there is a limit of 200 rows for upserts, so I&#8217;ve changed the Upsert() method as below to divide and submit the upserts in batches of 200 items at a time. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[13],"tags":[],"class_list":["post-53","post","type-post","status-publish","format-standard","hentry","category-no-category"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/posts\/53","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/comments?post=53"}],"version-history":[{"count":0,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/posts\/53\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/media?parent=53"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/categories?post=53"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/tags?post=53"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}