+ Start a Discussion
Craig PCraig P 

How to add JavaScript confirm to a custom button using a Visualforce page

I have a custom button on the Contact object which uses a Visualforce page to send an email and create a Task.  It is working fine.

 

Requirement:

I need to add a confirmation (e.g., "are you sure you want to send an email?") to the button, but I cannot use JavaScript on the button itself because I am invoking a Visualforce page.

 

Also, I cannot add JavaScript to the Visualforce page, because I am using the action attribute on the <apex:page> element

 

Is there a way to automatically invoke a JavaScript function from the <apex:page> element?  Is there any way to have a JavaScript confirm on a custom button that is using a Visualforce page?

 

Thanks in advance!

Adil_SFDCAdil_SFDC

Can you not use another VF Page which has Confirm and Cacel Button. 

When user clicks confirm then u can have Send email functionality on Confirm button . 

Craig PCraig P

The visualforce page is automatically sending the email and creating the task b/c I am using the <apex:page action="doSomething">

 

I do not want to make the user experience to be:

1) on Contact detail page, click custom button to display VF page

2) on VF page, click the send email button

3) have JavaScript confirm window  pop up

4) click OK on confirm button to send email & create Task

 

I want the user experience to be:

1) on the Contact detail page, click custom button

2) have JavaScript confirm window pop up

3) click OK on confirm button to send email & create Task

CproCpro

Update:

I ended up changing the button to use JavaScript to invoke a web service which created the task and sent the email.  In the JavaScript, just prior to invoking the web service I put a JS confirm( ) call.

 

{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}

confirm("Are you sure you want to send an email to the Advisor?");
var resultMsg = sforce.apex.execute("RevCultContact","createTaskAndSendEmail", {contactId:"{!Contact.Id}"});
window.parent.location.reload();

 simple & straigh forward...

 

 

Naveen KNNaveen KN
Implement custom dialog box in salesforce lightning 

https://www.codekiat.com/2019/07/confirm-dialog-in-salesforce-lightning.html

--
Naveen K N