This Trigger is being created to update a lookup field on Contact if the Contacts Community account is disabled.
I have a field on Contact called Support_Community_User__c that is a lookup to User which gets assigned the User.Id of the Contacts related Community User Id upon Community account creation. This is done via a separate Trigger.
What I am trying to accomplish with this Trigger is if we Disable a Customer User via the Manage External User Button on Contact which unchecks the Active checkbox on the related user and removes the relationship to the Contact in the Contact field on User, I want to remove the User.Id from the Support_Community_User__c field on Contact.
Here is my attempt that is not updating the Contact as I would expect and I am unsure why.
trigger CommunityUserContactRemove on User (after update) {
Profile p = [SELECT Id FROM Profile WHERE Name = 'Quatro Community Login User'];
List<Contact> userContacts = new List<Contact>();
for (User u : trigger.new) {
User oldUser = Trigger.oldMap.get(u.Id);
if (u.ContactId == null & u.ProfileId == p.Id){
userContacts.add(new Contact(
Id = oldUser.ContactId,
Support_Community_User__c = null));
}
}
update userContacts;
}