• Michael Henderson
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Hello,

We have added a field "Assign to" on Case (a lookup on user) to let Salesforce.com users the ability to change the owner of a case from the case list. The Case owner is then updated via a trigger (before update on case) that is copying the "Assign to" field value into the Case.owner field.

The trigger works fine and the case owner is updated correctly.

The issue is that when the case owner is updated via that procedure, an automatic email is sent to the new Case owner to warn him that he s now assigned to the case. We do NOT want this email to be sent.

How can we prevent that email to be sent? Is there a piece of code available for that?


Here is the code I'm using currently:

trigger AssignToCaseOwner on Case (before update) {
	Integer i = 0;
	for(Case theCase : System.Trigger.new)
	{
		// only executed if the case owner is not changed as well 
		// and if the case owner is not already the "Assign to" user
		if(theCase.OwnerId == System.Trigger.old.get(i).OwnerId && 
			theCase.Assign_to__c != null && 
			theCase.Assign_to__c != System.Trigger.old.get(i).Assign_to__c && 
			theCase.OwnerId != theCase.Assign_to__c)
		{
			theCase.OwnerId = theCase.Assign_to__c;
			// set DML options to remove the auto email -> NOT WORKING
			Database.DMLOptions dlo = new Database.DMLOptions();
			dlo.EmailHeader.triggerUserEmail = false;
			theCase.setOptions(dlo);
		}
		
		// Make the "Assign to" field empty as we do not need the value 
		// to be stored in the record
		theCase.Assign_to__c = null;
	
		i++;
	}
}

 

 

Thanks on beforehand,
Martin HUBERT.