2

Is there a way to delete multiple Components using the Core Service?

I wanted to delete the components from the CMS using core service. currently, I am performing as below, but when there are 100s of components, it takes lots of time as it does call to service for 100 times. Is there a way to delete all these 100 components at a time??

foreach (var offerComponentToDelete in existingOfferComponents)
{  
    Client.Delete(offerComponentToDelete.Attribute("ID").Value);
}
4
  • 2
    Yes, there is a way. Jul 5, 2017 at 16:51
  • 5
    This question is so lacking in detail that it's unlikely to help anyone. Nick's answer in the comment above this is about as good as it's going to get. Please spend some time to describe your scenario, and what your problem is. What did you try already? Why didn't it work? What ideas do you have about what might be wrong? Jul 5, 2017 at 17:08
  • Updated my question
    – Rafeeq
    Jul 6, 2017 at 6:46
  • Even I have a similar requirement. I create thousands of components using core service. After some testing again I want to delete all of them. If I try to delete manually it takes lot of time. So suggest an approach to delete the components in bulk using core service or some other logic. Sep 22, 2017 at 2:30

1 Answer 1

10

As the comments indicate your original question lacked a lot of information, your edit does provide a bit more information, however they don't really show a lot of effort from you in looking for an answer yourself.

You seem to have found the Core Service API already, and I do suggest checking out the API documentation for it in more detail (it can be downloaded here https://docs.sdl.com/LiveContent/content/en-US/SDL%20Web-v5/GUID-2301148A-E3EA-43EF-A2FC-7D3C9BAEE8FF). Once you do, you might stumble upon the ICoreServiceBatch201501 Interface with the description:

This interface provides functionality for creating predefined Batch operation.

Looking into its methods you will find the ICoreServiceBatch201501.BatchDelete method, which takes a list of input items. Using this method will decrease the amount of calls from the Core Service to the CM core to one, but keep in mind, deleting an item is a heavy operation, since all the references of that item need to be checked, and it will fail when the item is in use.

1
  • 2
    make sure your batch service is running on CMS server
    – Raj Kumar
    Jul 6, 2017 at 7:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.