/// <summary> /// Inserts or Updates a records based on external id /// </summary> /// <param name="sObjectTypeName">SObject name, e.g. "Account"</param> /// <param name="fieldName">External ID field name</param> /// <param name="fieldValue">External ID field value</param> /// <param name="sObject">Object to update</param> /// <param name="customHeaders">Custom headers to include in request (Optional). await The HeaderFormatter helper class can be used to generate the custom header as needed.</param> /// <returns>CreateResponse object, includes new object's ID if record was created and no value if object was updated</returns> /// <exception cref="ForceApiException">Thrown when request fails</exception> public async Task <CreateResponse> InsertOrUpdateRecord <T>(string sObjectTypeName, string fieldName, string fieldValue, T sObject, Dictionary <string, string> customHeaders = null) { var uri = UriFormatter.SObjectRowsByExternalId(InstanceUrl, ApiVersion, sObjectTypeName, fieldName, fieldValue); JsonClient client = new JsonClient(AccessToken, _httpClient); return(await client.HttpPatchAsync <CreateResponse>(sObject, uri, customHeaders)); }
/// <summary> /// Inserts or Updates a records based on external id /// </summary> /// <param name="sObjectTypeName">SObject name, e.g. "Account"</param> /// <param name="fieldName">External ID field name</param> /// <param name="fieldValue">External ID field value</param> /// <param name="sObject">Object to update</param> /// <param name="customHeaders">Custom headers to include in request (Optional). await The HeaderFormatter helper class can be used to generate the custom header as needed.</param> /// <returns>CreateResponse object, includes new object's ID if record was created and no value if object was updated</returns> /// <exception cref="ForceApiException">Thrown when request fails</exception> public async Task <CreateResponse> InsertOrUpdateRecord <T>(string sObjectTypeName, string fieldName, string fieldValue, T sObject, Dictionary <string, string> customHeaders = null) { Dictionary <string, string> headers = new Dictionary <string, string>(); //Add call options Dictionary <string, string> callOptions = HeaderFormatter.SforceCallOptions(ClientName); headers.AddRange(callOptions); //Add custom headers if specified if (customHeaders != null) { headers.AddRange(customHeaders); } var uri = UriFormatter.SObjectRowsByExternalId(InstanceUrl, ApiVersion, sObjectTypeName, fieldName, fieldValue); JsonClient client = new JsonClient(AccessToken, _httpClient); return(await client.HttpPatchAsync <CreateResponse>(sObject, uri, headers)); }