trigger ECHOdeleteDepartmentManagerRecord on User (after update) {
List<Id> inactiveUserIds = new List<Id>();
for (User updatedUser : Trigger.new) {
User oldUser = Trigger.oldMap.get(updatedUser.Id);
// Check if the User record was updated to be "Inactive"
if (updatedUser.IsActive == false && oldUser.IsActive == true) {
inactiveUserIds.add(updatedUser.Id);
}
}
if (!inactiveUserIds.isEmpty()) {
List<ECM_Department_Managers__c> departmentManagerRecordsToDelete = [
SELECT Id
FROM ECM_Department_Managers__c
WHERE ECHO_Department_Manager_userId__c IN :inactiveUserIds
];
if (!departmentManagerRecordsToDelete.isEmpty()) {
delete departmentManagerRecordsToDelete;
}
}
In this code , im attemping to delete a record from a custom object . The custom object is a table that stores department managers. On the record , i have a formula field that shows the department managers UserId.
If a user is set to "inactive" I want my trigger to fire and delete the corresponding department manager record in my custom object.
I tried doing this in flow with a scheduled path but still it didnt work.
:(
That's why I told you to check if there is any permission or not.