Exemplo n.º 1
0
        /// <summary>
        /// Deletes the specified identifier list.
        /// </summary>
        /// <param name="idList">The identifier list.</param>
        /// <returns>System.Int32.</returns>
        /// <exception cref="System.Exception"></exception>
        public int Delete(List <string> idList)
        {
            if (idList.Count <= 0)
            {
                return(0);
            }

            //Need to partition 200 at a time because salesforce limit.
            var partitionedIds = idList.Partition(200);
            var deleteResults  = new List <DeleteResult>();

            foreach (var ids in partitionedIds)
            {
                deleteResults.AddRange(_binding.delete(ids.ToArray()));
            }

            if (deleteResults.All(sr => sr.success))
            {
                return(deleteResults.Count);
            }

            var errorString = string.Join(string.Empty, deleteResults.Where(sr => !sr.success)
                                          .Select(
                                              (sr, i) => $"\r\n\tError {i}:\r\n\t\t" + string.Join("\r\n\t\t", sr.errors.Select(e => e.message))));

            throw new Exception($"Salesforce delete failed with following errors: {errorString}");
        }
Exemplo n.º 2
0
        public ActionResult Delete()
        {
            DeleteResult[] deleteResults = sfdcBinding.delete(new string[] { "01t28000004sWTyAAM" });

            if (deleteResults[0].success)
            {
                string id = deleteResults[0].id;
                Response.Write("<br/>ID:" + id);
                Response.Write("<br/>DELETE Product Successfully!!!");
            }
            else
            {
                string result = deleteResults[0].errors[0].message;
                Response.Write("<br/>ERROR:" + result);
            }

            return(View("Index"));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Deletes Salesforce object by ID.
        /// </summary>
        /// <param name="id"></param>
        /// <returns>True if deleted.</returns>
        public bool DeleteObject(string id)
        {
            bool result = false;

            if (CheckConnected())
            {
                if (!String.IsNullOrEmpty(id))
                {
                    DeleteResult[] deleteResults = _binding.delete(new string[] { id });

                    result = ((deleteResults.Length > 0) && (deleteResults[0].success));
                }
                else
                {
                    throw (new InvalidOperationException(Errors.ERR_ID_FIELD_IS_NOT_SET));
                }
            }

            return(result);
        }
Exemplo n.º 4
0
        public void DeleteSalesForceLead(string leadID)
        {
            SforceService SfdcBinding = SalesForceSession();
            List <string> ids         = new List <string>();

            ids.Add(leadID);
            DeleteResult[] deleteResults = SfdcBinding.delete(ids.ToArray());


            if (deleteResults[0].success)
            {
                string Id = "";
                Id = deleteResults[0].id;
            }
            else
            {
                string result = "";
                result = deleteResults[0].errors[0].message;
            }
        }
Exemplo n.º 5
0
        public void DeleteSObjects(string sobjectName, string[] idarray)
        {
            LoginIfRequired();

            if (!_salesforceSession.AllowDeletion())
            {
                throw new ApplicationException("This app will not allow deletion to be run on target database");
            }

            var deleteResults = _binding.delete(idarray);

            int           successCount  = 0;
            int           errorCount    = 0;
            List <string> errorMessages = new List <string>();

            foreach (DeleteResult resLoop in deleteResults)
            {
                if (resLoop.success)
                {
                    successCount += 1;
                }
                else
                {
                    errorCount += 1;
                    string errMess = string.Format("delete of {0} {1} failed message {2}",
                                                   sobjectName, resLoop.id, string.Join(", ", resLoop.errors.Select(e => e.message)));
                    logger.DebugFormat(errMess);
                    errorMessages.Add(errMess);
                }
            }
            logger.DebugFormat("deletion of {0} - {1} success {2} failed",
                               sobjectName, successCount, errorCount);
            if (errorCount > 0)
            {
                throw new ApplicationException(string.Format("deletion of {0} - {1} failed {2}",
                                                             sobjectName, errorCount, string.Join(", ", errorMessages)));
            }
        }
Exemplo n.º 6
0
        private void deleteBtn_Click(object sender, EventArgs e)
        {
            String[] ids = new String[dataCallList.SelectedItems.Count];
            for (int i = 0; i < dataCallList.SelectedItems.Count; i++)
            {
                ids[i] = dataCallList.SelectedItems[i].Text;
            }

            DeleteResult[] deleteResults = SfdcBinding.delete(ids);
            DeleteResult   deleteResult  = deleteResults[0];

            if (deleteResult.success)
            {
                MessageBox.Show("Record ID " + deleteResult.id + " deleted succesfully.");
                foreach (ListViewItem eachItem in dataCallList.SelectedItems)
                {
                    dataCallList.Items.Remove(eachItem);
                }
            }
            else
            {
                MessageBox.Show("Delete failed");
            }
        }
Exemplo n.º 7
0
 internal DeleteResult[] DeleteItems(string[] ids)
 {
     return(_sforceService.delete(ids));
 }