• sshawkins
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
I have a requirement to make the Case object's ContactId field to Null when the owner of the case changes. Understand that the contactId is populated by salesforce standard process based on the case owner. But is there anyway i can achieve this.?

Tried calling a Queueable class to update case record on Case After update trigger, but it still did not work when the owner is community user.
Please suggest. below is the Queueable class called from case after update trigger context. (used after update context even though update is on same object, tried before update and could see ContactId was getting updated back to case owner)
 
public class CaseContactUpdateQueueable implements Queueable {
    private Map<Id,Case> newMap;
    public CaseContactUpdateQueueable(Map<Id,Case> newMap) {
        this.newMap = newMap;
    }
    public void execute(QueueableContext context) {
        List<Case> caseList = new List<Case>();

        for(Case cs:newMap.values()){
           if(cs.ContactId != null)){
               caseList.add(new Case(Id = cs.Id,ContactId = null));
            }
        }

        update caseList;
    }
}