CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY error while updating a record in Copado

While updating the status of a record in Copado (for example a Deployment Job or a Promotion), you might face the following exception:

Error: copado.PromotionTrigger: execution of AfterUpdate caused by: System.ListException: Duplicate id in list: a1M1t000002Bon4EAC (copado)

User-added image

This might be caused by a User Story duplicated in the Promotion record, most likely because it is included as part of a User Story Bundle.

If you include a User Story Bundle along with one of the User Stories that are part of the bundle in the same Promotion record, you probably will face this error.

Once a Promotion status is changed to "Complete" we will try to update the User Story records using the trigger displayed on the error above. Since the User Story is present twice: once itself and once as part of a bundle, the record is duplicated in the trigger, and therefore, it is throwing this exception.


Workaround:
Since from the Copado perspective, there is no business case for adding a User Story bundle and the same User Story that is part of that bundle in the same Promotion record, the workaround here is to exclude the User Story mentioned in the error (please, note that the error contains the record ID for the affected User Story) and leaving only the User Story bundle in the Promotion.



How did we do?