public async void GetBatchResultAsync_NullJobId_ArgumentNullException() { var client = new ForceClient("test", "test", "v32"); await client.GetBatchResultAsync("test", null); // expects exception }
public async void GetBatchResultAsync_NullBatchInfo_ArgumentNullException() { IForceClient client = new ForceClient("test", "test", "v32"); await client.GetBatchResultAsync(null); // expects exception }
public async Task GetBatchResultAsync_NullBatchId_ArgumentNullException() { var client = new ForceClient("test", "test", "v32"); await client.GetBatchResultAsync(null, "test"); // expects exception }
private static async Task RunSample() { var auth = new AuthenticationClient(); // Authenticate with Salesforce Console.WriteLine("Authenticating with Salesforce"); var url = IsSandboxUser.Equals("true", StringComparison.CurrentCultureIgnoreCase) ? "https://test.salesforce.com/services/oauth2/token" : "https://login.salesforce.com/services/oauth2/token"; await auth.UsernamePasswordAsync(ConsumerKey, ConsumerSecret, Username, Password, url); Console.WriteLine("Connected to Salesforce"); // Get a bulk client var client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion); // create a job var jobInfo = await client.CreateJobAsync("Account", BulkConstants.OperationType.Insert); Console.WriteLine("Created a Job"); // Make a dynamic typed Account list var dtAccountsBatch1 = new SObjectList <SObject> { new SObject { { "Name", "TestDtAccount1" } }, new SObject { { "Name", "TestDtAccount2" } }, new SObject { { "MADEUPFIELD", "MADEUPVALUE" } }, new SObject { { "Name", "TestDtAccount3" } } }; // Make a dynamic typed Account list var dtAccountsBatch2 = new SObjectList <SObject> { new SObject { { "Name", "TestDtAccount4" } }, new SObject { { "Name", "TestDtAccount5" } }, new SObject { { "Name", "TestDtAccount6" } } }; // Make a dynamic typed Account list var dtAccountsBatch3 = new SObjectList <SObject> { new SObject { { "MADEUPFIELD", "MADEUPVALUE" } }, new SObject { { "Name", "TestDtAccount7" } }, new SObject { { "Name", "TestDtAccount8" } }, new SObject { { "Name", "TestDtAccount9" } } }; // create the batches var batchInfoList = new List <BatchInfoResult> { await client.CreateJobBatchAsync(jobInfo, dtAccountsBatch1), await client.CreateJobBatchAsync(jobInfo, dtAccountsBatch2), await client.CreateJobBatchAsync(jobInfo, dtAccountsBatch3) }; Console.WriteLine("Created Three Batches"); // poll var pollStart = 1.0f; const float pollIncrease = 2.0f; var completeList = new List <BatchInfoResult>(); while (batchInfoList.Count > 0) { var removeList = new List <BatchInfoResult>(); foreach (var batchInfo in batchInfoList) { var newBatchInfo = await client.PollBatchAsync(batchInfo); if (newBatchInfo.State.Equals(BulkConstants.BatchState.Completed.Value()) || newBatchInfo.State.Equals(BulkConstants.BatchState.Failed.Value()) || newBatchInfo.State.Equals(BulkConstants.BatchState.NotProcessed.Value())) { completeList.Add(newBatchInfo); removeList.Add(batchInfo); } } foreach (var removeInfo in removeList) { batchInfoList.Remove(removeInfo); } await Task.Delay((int)pollStart); pollStart *= pollIncrease; } // get results var results = new List <BatchResultList>(); foreach (var completeBatch in completeList) { results.Add(await client.GetBatchResultAsync(completeBatch)); } Console.WriteLine("All Batches Complete, \"var results\" contains the result objects (Each is a list containing a result for each record):"); foreach (var result in results.SelectMany(resultList => resultList.Items)) { Console.WriteLine("Id:{0}, Created:{1}, Success:{2}, Errors:{3}", result.Id, result.Created, result.Success, result.Errors != null); if (result.Errors != null) { Console.WriteLine("\tErrors:"); var resultErrors = result.Errors; foreach (var field in resultErrors.Fields) { Console.WriteLine("\tField:{0}", field); } Console.WriteLine("\t{0}", resultErrors.Message); Console.WriteLine("\t{0}", resultErrors.StatusCode); } } }
private static async Task RunSample() { var auth = new AuthenticationClient(); // Authenticate with Salesforce Console.WriteLine("Authenticating with Salesforce"); var url = IsSandboxUser.Equals("true", StringComparison.CurrentCultureIgnoreCase) ? "https://test.salesforce.com/services/oauth2/token" : "https://login.salesforce.com/services/oauth2/token"; await auth.UsernamePasswordAsync(ConsumerKey, ConsumerSecret, Username, Password, url); Console.WriteLine("Connected to Salesforce"); // Get a bulk client var client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion); // create a job var jobInfo = await client.CreateJobAsync("Account", BulkConstants.OperationType.Insert); Console.WriteLine("Created a Job"); // Make a dynamic typed Account list var dtAccountsBatch1 = new SObjectList<SObject> { new SObject{{"Name", "TestDtAccount1"}}, new SObject{{"Name", "TestDtAccount2"}}, new SObject{{"MADEUPFIELD", "MADEUPVALUE"}}, new SObject{{"Name", "TestDtAccount3"}} }; // Make a dynamic typed Account list var dtAccountsBatch2 = new SObjectList<SObject> { new SObject{{"Name", "TestDtAccount4"}}, new SObject{{"Name", "TestDtAccount5"}}, new SObject{{"Name", "TestDtAccount6"}} }; // Make a dynamic typed Account list var dtAccountsBatch3 = new SObjectList<SObject> { new SObject{{"MADEUPFIELD", "MADEUPVALUE"}}, new SObject{{"Name", "TestDtAccount7"}}, new SObject{{"Name", "TestDtAccount8"}}, new SObject{{"Name", "TestDtAccount9"}} }; // create the batches var batchInfoList = new List<BatchInfoResult> { await client.CreateJobBatchAsync(jobInfo, dtAccountsBatch1), await client.CreateJobBatchAsync(jobInfo, dtAccountsBatch2), await client.CreateJobBatchAsync(jobInfo, dtAccountsBatch3) }; Console.WriteLine("Created Three Batches"); // poll var pollStart = 1.0f; const float pollIncrease = 2.0f; var completeList = new List<BatchInfoResult>(); while (batchInfoList.Count > 0) { var removeList = new List<BatchInfoResult>(); foreach (var batchInfo in batchInfoList) { var newBatchInfo = await client.PollBatchAsync(batchInfo); if (newBatchInfo.State.Equals(BulkConstants.BatchState.Completed.Value()) || newBatchInfo.State.Equals(BulkConstants.BatchState.Failed.Value()) || newBatchInfo.State.Equals(BulkConstants.BatchState.NotProcessed.Value())) { completeList.Add(newBatchInfo); removeList.Add(batchInfo); } } foreach (var removeInfo in removeList) { batchInfoList.Remove(removeInfo); } await Task.Delay((int) pollStart); pollStart *= pollIncrease; } // get results var results = new List<BatchResultList>(); foreach (var completeBatch in completeList) { results.Add(await client.GetBatchResultAsync(completeBatch)); } Console.WriteLine("All Batches Complete, \"var results\" contains the result objects (Each is a list containing a result for each record):"); foreach (var result in results.SelectMany(resultList => resultList.Items)) { Console.WriteLine("Id:{0}, Created:{1}, Success:{2}, Errors:{3}", result.Id, result.Created, result.Success, result.Errors != null); if (result.Errors != null) { Console.WriteLine("\tErrors:"); var resultErrors = result.Errors; foreach (var field in resultErrors.Fields) { Console.WriteLine("\tField:{0}", field); } Console.WriteLine("\t{0}", resultErrors.Message); Console.WriteLine("\t{0}", resultErrors.StatusCode); } } }