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
mworldmworld 

Delete Confirmation Message Box

Using VF, I have modified some of my related lists to display additional columns of information (from objects not available in the "stock" lists). Beyond that I want these re-created lists to look and feel the same as the "stock" ones. And they do, with just one exception: there is no confirmation that pops up when the Del link is clicked.
 
Code:
<apex:outputLink value="/setup/own/deleteredirect.jsp">Del
     <apex:param name="Id" value="{!priority.ID_3__c}"/>
     <apex:param name="delID" value="{!priority.ID_1__c}"/>
     <apex:param name="retURL" value="/{!priority.ID_3__c}"/>
</apex:outputLink>

As you can see the link has the same URL as the stock link and the params provide the needed information from the controller extension. What do I need to do to get the confirmation pop-up? The users are paranoid about accidentally deleting something.
 
Thanks,
 
Mauricio
Ron HessRon Hess
Take a look at how this is done on a normal ( non visualforce ) page (using view source) and you can see that there is a javascript snippet that runs to ask you if you are sure you want to delete.

You can add such a question as onsubmit for the form or onclick on the output link, i believe.  I've not tried this yet.


mworldmworld

I've got the onClick in there and it does bring up the confirmation box but do I have a way of getting the required query string parameters in there? I've tried adding '?Id={!priority.ID_3__c}' at the end of the URL or just using {0} and neither manages to get the data in there. Any ideas?

Code:
<apex:outputLink onClick="if ((Modal.confirm && Modal.confirm('Are you sure—')) || (!Modal.confirm && window.confirm('Are you sure–'))) navigateToUrl('/setup/own/deleteredirect.jsp')">Del
     <apex:param name="Id" value="{!priority.ID_3__c}"/>
     <apex:param name="delID" value="{!priority.ID_1__c}"/>
     <apex:param name="retURL" value="/{!priority.ID_3__c}"/>
</apex:outputLink>

Thanks,

Mauricio
 

Ron HessRon Hess
you may have to urlescape the chars that you append to the deleteredirect JSP
mworldmworld

Here's what worked:

Code:
<apex:outputLink value="/setup/own/deleteredirect.jsp" onClick="return confirmDelete()">Del
     <apex:param name="Id" value="{!attorney.ID_5__c}"/>
     <apex:param name="delID" value="{!attorney.ID_1__c}"/>
     <apex:param name="retURL" value="/{!attorney.ID_5__c}"/>
</apex:outputLink></B>

I kept digging around the page with view source and noticed that some of the delete links called confirmDelete() instead of having the inline snippet from above. Not sure why it's done two different ways but nevertheless, this works.

 

Mauricio
 

iffuiffu

Thanks mworld for sharing the code.....and here is the code for javascript function confirmDelete(), incase other readers may want to utilize.

 

 <script language="javascript">
        function confirmDelete(){
            if(confirm('Are you sure you want to delete?'))
                return true;
            return false;
        }
    </script>

 

Cheers!

pinkelkpinkelk

For Command Links or Buttons, it is a lot simpler than that:

 

<apex:commandLink value="Remove" onclick="return confirm('Are you sure?')" action="{!removeMember}" >

     <apex:param name="removeMemberId" value="{!m.Id}" assignTo="{!selectedMemberId}" />

</apex:commandLink>

 

If the onclick call to confirm() returns false, the action is not called.   That's all you need.

ColinMcGColinMcG

Pinkelk, thank you! There are a number of untidy solutions which have been posted in various places, but this is perfect. I'm not sure I understand why it works, as I would have expected onclick to be independent of the action. Anyway, this helped me out, so thanks again.

CodeFinderCodeFinder

@pinkelk 

 

This works perfect. Thank you. 

 

Bharath