Search code examples
javascriptsalesforceapex-codevisualforce

Override a standard button in Salesforce page


I'm trying to override a standard button (delete) in a Salesforce page. I overrode it with a Visualforce Page but the problem I'm facing is the pop up blocker.

The purpose of overriding the button is to ask the user whether he/she wants to delete the file and do the deletion on the third party host.

Is there any way I can either stop the pop up blocker or use another overriding approach? My visualforce page contains a js script that will open a pop up window. I'm wondering if I can put this js script in a different place!

<apex:page standardController="" showheader="false" sidebar="false"> 
    <apex:includeScript value=""/>
    <apex:includeScript value=""/>
        <script language="javascript"> 
            var caseStatus = "{!s__c}";
            try{
                sforce.connection.sessionId = "{!$Api.Session_ID}";
                var isPortalUser = sforce.apex.execute('e','r',{}); 
            }catch(e) {
                alert(e)
            }

                if(caseStatus == "A"){
                window.open('{!$Label.FTP_Attachment_Pro_URL}/sforce/ftp/Delete.aspx?ID={!ENZ__FTPAttachment__c.Id}&OrgID={!$Organization.Id}&SFUrl={!$Label.API_URL}/{!$Organization.Id}&SFSessionID={!$Api.Session_ID}',500,600);
            window.location = '{!$Label.SF_Base_URL}/{!ENZ__FTPAttachment__c.Case__c}';

            }
               else{
                    window.location = '{!$La}';
                    window.alert("a"+ caseStatus);
                } 

    </script> 
</apex:page>

Solution

  • Don't use window.open as that can get blocked as it is a popup.

    If you don't want a fancy confirmation box you can use javascript confirm function

    if (confirm('are you sure you want to delete?')) {
      // delete
    } else {
      // error
    }
    

    If you need fancy way of asking for it use a modal box instead as seen on http://jqueryui.com/demos/dialog/ there is many available on the net that are easy to use and can work with other libraries or without any (the jqueryui link is merely to illustrate the dialog box.

    Here is a good one with a demo as a confirmation modal box (last demo on the page)

    http://www.ericmmartin.com/projects/simplemodal-demos/