src/SFBulkAPIStarterTest/TestBulkApiClient.cs
/// <summary>
/// Tests deleting an account record that is initially inserted.
/// </summary>
Tests deleting an account record that is initially inserted.
Tests deleting an account record that is initially inserted .
[TestMethod]
        public void DeleteAccountTest()
        {
            CreateJobRequest jobRequest = buildDefaultInsertAccountCreateJobRequest();
            Job job = _apiClient.CreateJob(jobRequest);
            String batchContents = buildDefaultAccountBatchContents();
            CreateBatchRequest batchRequest = buildCreateBatchRequest(job.Id, batchContents);
            Batch accountBatch = _apiClient.CreateBatch(batchRequest);
            _apiClient.CloseJob(job.Id);
            job = _apiClient.GetCompletedJob(job.Id);
            CreateJobRequest queryAccountJobRequest = buildDefaultQueryAccountCreateJobRequest();
            Job queryJob = _apiClient.CreateJob(queryAccountJobRequest);
            String accountQuery = "SELECT Id FROM Account WHERE Name = '" + DEFAULT_ACCOUNT_NAME + "'";
            CreateBatchRequest queryBatchRequest = buildCreateBatchRequest(queryJob.Id, accountQuery);
            queryBatchRequest.BatchContentType = BatchContentType.CSV;
            Batch queryBatch = _apiClient.CreateBatch(queryBatchRequest);
            _apiClient.CloseJob(queryJob.Id);
            queryJob = _apiClient.GetCompletedJob(queryJob.Id);
            String batchQueryResultsList = _apiClient.GetBatchResults(queryBatch.JobId, queryBatch.Id);
            List<String> resultIds = _apiClient.GetResultIds(batchQueryResultsList);
            Assert.AreEqual(1, resultIds.Count);
            String batchQueryResults = _apiClient.GetBatchResult(queryBatch.JobId, queryBatch.Id, resultIds[0]);
            String[] batchQueryResultsParts = batchQueryResults.Split(new String[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
            String firstAccountIdToDelete = batchQueryResultsParts[1].Replace(@"""", String.Empty);
            CreateJobRequest deleteAccountJobRequest = buildDefaultDeleteAccountCreateJobRequest();
            Job deleteJob = _apiClient.CreateJob(deleteAccountJobRequest);
            String deleteBatchContents = "Id" + Environment.NewLine + firstAccountIdToDelete;
            CreateBatchRequest deleteBatchRequest = buildCreateBatchRequest(deleteJob.Id, deleteBatchContents);
            Batch deleteBatch = _apiClient.CreateBatch(deleteBatchRequest);
            _apiClient.CloseJob(deleteJob.Id);
            deleteJob = _apiClient.GetCompletedJob(deleteJob.Id);
            Assert.AreEqual(1, deleteJob.NumberRecordsProcessed);
        }
[ TestMethod ] public void DeleteAccountTest ( ) { CreateJobRequest jobRequest = buildDefaultInsertAccountCreateJobRequest ( ) ; Job job = _apiClient . CreateJob ( jobRequest ) ; String batchContents = buildDefaultAccountBatchContents ( ) ; CreateBatchRequest batchRequest = buildCreateBatchRequest ( job . Id , batchContents ) ; Batch accountBatch = _apiClient . CreateBatch ( batchRequest ) ; _apiClient . CloseJob ( job . Id ) ; job = _apiClient . GetCompletedJob ( job . Id ) ; CreateJobRequest queryAccountJobRequest = buildDefaultQueryAccountCreateJobRequest ( ) ; Job queryJob = _apiClient . CreateJob ( queryAccountJobRequest ) ; String accountQuery = " " + DEFAULT_ACCOUNT_NAME + " " ; CreateBatchRequest queryBatchRequest = buildCreateBatchRequest ( queryJob . Id , accountQuery ) ; queryBatchRequest . BatchContentType = BatchContentType . CSV ; Batch queryBatch = _apiClient . CreateBatch ( queryBatchRequest ) ; _apiClient . CloseJob ( queryJob . Id ) ; queryJob = _apiClient . GetCompletedJob ( queryJob . Id ) ; String batchQueryResultsList = _apiClient . GetBatchResults ( queryBatch . JobId , queryBatch . Id ) ; List < String > resultIds = _apiClient . GetResultIds ( batchQueryResultsList ) ; Assert . AreEqual ( 1 , resultIds . Count ) ; String batchQueryResults = _apiClient . GetBatchResult ( queryBatch . JobId , queryBatch . Id , resultIds [ 0 ] ) ; String [ ] batchQueryResultsParts = batchQueryResults . Split ( new String [ ] { " \n " } , StringSplitOptions . RemoveEmptyEntries ) ; String firstAccountIdToDelete = batchQueryResultsParts [ 1 ] . Replace ( @"""" , String . Empty ) ; CreateJobRequest deleteAccountJobRequest = buildDefaultDeleteAccountCreateJobRequest ( ) ; Job deleteJob = _apiClient . CreateJob ( deleteAccountJobRequest ) ; String deleteBatchContents = " " + Environment . NewLine + firstAccountIdToDelete ; CreateBatchRequest deleteBatchRequest = buildCreateBatchRequest ( deleteJob . Id , deleteBatchContents ) ; Batch deleteBatch = _apiClient . CreateBatch ( deleteBatchRequest ) ; _apiClient . CloseJob ( deleteJob . Id ) ; deleteJob = _apiClient . GetCompletedJob ( deleteJob . Id ) ; Assert . AreEqual ( 1 , deleteJob . NumberRecordsProcessed ) ; }
Tests deleting an account record that is initially inserted.
Tests deleting an account record that is initially inserted .
// Insert an account so there's at least one to delete // Query the accounts to dynamically retreive the account id to delete // Close job so no more batches are added. // Delete the account // Close job so no more batches are added.