I want to write a trigger that will mark a checkbox on the contact object once a user clicks on the 'Manage External Users'->'Disable Customer User'
This is the trigger I wrote, it does not run when I click on the disable customer user:
trigger User on User(after insert, after update) {
Set < Id > contactIds = new Set < Id > ();
for (User u: Trigger.new) {
if (u.ContactId == null && Trigger.oldmap.get(u.id).ContactId != null) {
contactIds.add(Trigger.oldmap.get(u.id).ContactId);
}
if (contactIds.size() > 0) {
List < Contact > contacts = [select id, Has_Access_to_Customer_Portal__c from Contact where Id in: contactIds];
for (Contact c: contacts) {
c.Has_Access_to_Customer_Portal__c = false;
}
update contacts;
}
}
I guess the answer would be that the trigger object should be a contact, but I don't really know how to work it out.