You need to sign in to do that
Don't have an account?

Updating SelfServiceUser objects inside a trigger
Code:
We have a custom field that determines the status of a contact. If the contact is set to a "Former User" we would like to remove access to the case self service portal. However, I am having trouble updating the SelfServiceUser object inside of my after trigger. Also, any suggestions on how to improve efficiency of this code would be greatly appreciated.
trigger EndSSUAccessWhenContactIsSetToFormerUser on Contact bulk (after update) { Set<Id> lConIds = new Set<Id>(); for (Contact c : Trigger.new) { lConIds.add(c.Id); } List<SelfServiceUser> lSSUs = new List<SelfServiceUser>([select Id, IsActive, ContactId from SelfServiceUser where ContactId in :lConIds]); Map<Id,SelfServiceUser> lSelfServiceUsers = new Map<Id,SelfServiceUser>(); for(SelfServiceUser s: lSSUs) { lSelfServiceUsers.put(s.ContactId,s); } List<SelfServiceUser> lSelfServiceUserUpdates = new List<SelfServiceUser>(); for (Contact c : Trigger.new) { SelfServiceUser s = lSelfServiceUsers.get(c.Id); if(c.OMG_ContactType__c == 'Former User' && s != null && s.IsActive) { s.IsActive = false; lSelfServiceUserUpdates.add(s); if(lSelfServiceUserUpdates.size() == 200) { //update lSelfServiceUsersUpdates; lSelfServiceUserUpdates.clear(); } } } if(lSelfServiceUserUpdates.size() > 0) { //update lSelfServiceUsersUpdates; } }
We have a custom field that determines the status of a contact. If the contact is set to a "Former User" we would like to remove access to the case self service portal. However, I am having trouble updating the SelfServiceUser object inside of my after trigger. Also, any suggestions on how to improve efficiency of this code would be greatly appreciated.