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
RaviVarma123RaviVarma123 

Page should be closed when cancel button is clicked

Hi,
I have a visualforce page where when a button is clicked, it opens the standard lead edit page in the new tab to create a lead. When I click on the cancel button, it redirects to the previous page. But, all I need is when we click on the cancel button, the tab should be closed. I'm stuck with it since couple of days. Can anyone of you take the initiation of sorting this out for me.
Thanks
RV
Manj_SFDCManj_SFDC
yoou can override the button and create the custom code 
you can refer this  https://stackoverflow.com/questions/8921434/how-to-implement-cancel-functionality-in-a-visualforce-page
please mark the question as solved if this helps you
Manj_SFDCManj_SFDC
https://success.salesforce.com/answers?id=90630000000ZSzAAAW
https://success.salesforce.com/answers?id=90630000000gmEtAAI
Gaurish Gopal GoelGaurish Gopal Goel
Call javascript on click of your button like this:
<apex:commandButton value="Cancel" onclick="window.close();"/>
Gaurish Gopal GoelGaurish Gopal Goel
But it will only close the tab only when that tab has been opened by JavaScript. Its a security feature. If you have some validations on the page then you will have to use this syntax to override the validations:
<apex:commandButton value="Cancel" onclick="window.close();" immediate=true/>
Manj_SFDCManj_SFDC
Mark this as solved if this helps you, you too will fetch some points if the question is marked as solved :)
https://developer.salesforce.com/forums#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Developer_Forums&criteria=ALLQUESTIONS&id=9060G000000MVrtQAG
David Taber 1David Taber 1
This approach does not work when the JS is hosted in VF that's been called by LEX (e.g., a global action button).  Presumably, it could be made to work by sending a message the the LEX object that called the VF...as that context has control and can close the window.  Good luck figuring that little piece of code out.
David Taber 1David Taber 1
Ooooooooo, I just found out a nice workaround for the case where you have JS that's running in VF called by a LEX Global Action button.
The following script has to be included in your VF:
<script type='text/javascript' src='/canvas/sdk/js/publisher.js'></script>
Then use this line to close the Quick Action window:
Sfdc.canvas.publisher.publish({ name: "publisher.close", payload:{ refresh: "true" }});
Doesn't work every time (at least on my machine), but it works often enough to be very useful.
Thanks to notmyf4ulty in StackExchange for this