# Delete role via Rule including child objects

**URL:** <https://developer.sailpoint.com/discuss/t/delete-role-via-rule-including-child-objects/2012>\
**Category:** IIQ Discussion and Questions\
**Created:** [November 9, 2021, 12:50am UTC](https://developer.sailpoint.com/discuss/t/delete-role-via-rule-including-child-objects/2012 "2021-11-09T00:50:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![venus](https://avatars.discourse-cdn.com/v4/letter/v/35a633/32.png) [@venus](https://developer.sailpoint.com/discuss/u/venus)\
**Post date:** [November 9, 2021, 12:50am UTC](https://developer.sailpoint.com/discuss/t/delete-role-via-rule-including-child-objects/2012/1 "2021-11-09T00:50:05Z")

</div>

Hi All,

I am trying to delete a role using below code and gets a constraint error. I know IT roles has profiles and the error is related to complaining about the child records. What is the best to do a cascade delete of a role.

**The conflict occurred in database “identityiq”, table “identityiq.spt\_profile”, column ‘bundle\_id’.**

* * *

Scope scope = context.getObjectByName(Scope.class, project);  
if (scope != null) {  
QueryOptions qo = new QueryOptions();  
qo.addFilter(Filter.eq(“assignedScope.id”, scope.getId()));  
context.removeObjects(Bundle.class, qo);  
context.commitTransaction();  
}

* * *

Thanks in Advance

---

<div class="post-metadata">

**Author:** ![paul\_wheeler](https://avatars.discourse-cdn.com/v4/letter/p/cdc98d/32.png) [@paul\_wheeler](https://developer.sailpoint.com/discuss/u/paul_wheeler)\
**Post date:** [November 9, 2021, 8:17am UTC](https://developer.sailpoint.com/discuss/t/delete-role-via-rule-including-child-objects/2012/2 "2021-11-09T08:17:27Z")

</div>

@venus

For future reference, this should be posted under IdentityIQ, not IdentityNow.

You should use the sailpoint.api.Terminator class to delete objects in IdentityIQ. This ensures referential integrity is taken into account:

Terminator t = new Terminator(context);  
t.deleteObject(object);

---

<div class="post-metadata">

**Author:** ![venus](https://avatars.discourse-cdn.com/v4/letter/v/35a633/32.png) [@venus](https://developer.sailpoint.com/discuss/u/venus)\
**Post date:** [November 9, 2021, 3:55pm UTC](https://developer.sailpoint.com/discuss/t/delete-role-via-rule-including-child-objects/2012/3 "2021-11-09T15:55:09Z")

</div>

Thanks a lot Paul, will try this today.

---

<div class="post-metadata">

**Author:** ![venus](https://avatars.discourse-cdn.com/v4/letter/v/35a633/32.png) [@venus](https://developer.sailpoint.com/discuss/u/venus)\
**Post date:** [November 9, 2021, 5:46pm UTC](https://developer.sailpoint.com/discuss/t/delete-role-via-rule-including-child-objects/2012/4 "2021-11-09T17:46:49Z")

</div>

Works like a charm, thank a lot Paul again.

---

<div class="post-metadata">

**Author:** ![colin\_mckibben](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/colin_mckibben/32/37182_2.png) [@colin\_mckibben](https://developer.sailpoint.com/discuss/u/colin_mckibben)\
**Post date:** [November 10, 2021, 2:22pm UTC](https://developer.sailpoint.com/discuss/t/delete-role-via-rule-including-child-objects/2012/5 "2021-11-10T14:22:35Z")

</div>

@paul_wheeler, I moved this topic to the IIQ category. Thanks for catching it.

---

<div class="post-metadata">

**Author:** ![shreyacl](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@shreyacl](https://developer.sailpoint.com/discuss/u/shreyacl)\
**Post date:** [August 11, 2022, 6:15pm UTC](https://developer.sailpoint.com/discuss/t/delete-role-via-rule-including-child-objects/2012/6 "2022-08-11T18:15:52Z")

</div>

@venus I am using the following rule to execute a mass role deletion to be speicifc there are about 80k roles that needs to be deleted. I am using a run rule task and It takes about a day for the task to run and deletes about 500 roles and then either terminates itself or gives out an error - Can you please help me with what you exactly did and it worked for you?  
Here is the code being used -

String ROLE\_SUFFIX = “Role Ark”; //Name of the role goes here  
int rolecount = 0;  
Filter filter = Filter.and(Filter.like(“name”, ROLE\_SUFFIX, Filter.MatchMode.START));  
QueryOptions qo = new QueryOptions();  
qo.addFilter(filter);  
IncrementalObjectIterator iOitr = new IncrementalObjectIterator(context, Bundle.class, qo);  
while(iOitr.hasNext()){  
rolecount = rolecount + 1;  
Bundle role = iOitr.next();  
Terminator term = new Terminator(context);  
term.deleteObject(role);  
}

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sailpoint/original/2X/f/f2136700ed5e3703e0b85e02f6be799dacca7735.png) [@system](https://developer.sailpoint.com/discuss/u/system)\
**Post date:** [July 19, 2023, 2:25pm UTC](https://developer.sailpoint.com/discuss/t/delete-role-via-rule-including-child-objects/2012/7 "2023-07-19T14:25:21Z")

</div>


