function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
edoardo_spanoedoardo_spano 

Replicate "Send notification email to contact" checkbox on a Visualforce Page

Hi All,

I'm trying to replicate the standard "Send notification email to contact" checkbox, visible in the bottom of the Case edit page layout, in a custom Visualforce page.
If the user puts this flag, an email will be sent to the contact related to the case and this action will be historized as completed task, both in creation and editing.

I'm trying setting the "triggerAutoResponseEmail" parameter of the DMLOption class and passing this option in the update command.
This is my code:
public with sharing class MyController {

	private Case c;
	public Boolean sendEmail {get; set;}

	public MyController(ApexPages.StandardController ctrl) {
		c = (Case) ctrl.getRecord();
		sendEmail = false;
	}

	public PageReference save() {
		try {
			Database.DMLOptions dmo = new Database.DMLOptions();
			if(sendEmail) dmo.EmailHeader.triggerAutoResponseEmail = true;
			Database.update(c, dmo);
		} catch (Exception e) {}
	}

}

This code doesn't work because the parameter "triggerAutoResponseEmail" sends an email only after the case creation and not after editing.
How can I replicate the standard "Send notification email to contact" checkbox functionality via Apex?

Thank you in advance.
Edoardo
Shikha AgashiShikha Agashi
You have to built custom code for that in your controller. You can use ActionSupport component along with <Apex:inputcheckbox>. You can define your logic in method you are calling in actionSupport.
edoardo_spanoedoardo_spano
Hi Shikha,
the problem is not how I invoke the code, but that the code doesn't work as expected.

Edoardo
Shikha AgashiShikha Agashi
Can you please post the code along with vf page?
Shikha AgashiShikha Agashi
Ignore above code. I was in totally wrong direction. Please try below code:
 
public with sharing class MyController {

	private Case c;
	public Boolean sendEmail {get; set;}

	public MyController(ApexPages.StandardController ctrl) {
		c = (Case) ctrl.getRecord();
		sendEmail = false;
	}

	public PageReference save() {
		try {
			Database.DMLOptions dmo = new Database.DMLOptions();
			//Please try adding this line and see if it works.
			dmo.EmailHeader.triggerAutoResponseEmail = false;
			if(sendEmail) dmo.EmailHeader.triggerAutoResponseEmail = true;
			Database.update(c, dmo);
		} catch (Exception e) {}
	}

}