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
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student 

Apex Messages on Delete button

Hey there,

I have a tabbed account VF page, each one of these tabs is a child to Account. I have created an extension which allows me to delete records from the tabs without being re-directed away from the open tab. My question is, how do I go about adding the "are you sure?" message or something of my choosing when the user clicks on the delete button? Is it something that I add on page level, to the extension or a combination where the extension decides when the page message will appear.

Thank you for your help. I can provide my extension and delete buttons on request.
Best Answer chosen by Developer.mikie.Apex.Student
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
problem solved simply by adding this to each commandlink:

onclick="if(!confirm('Are you sure?')){return false;}"


Thank you for your help

All Answers

Adnubis LLCAdnubis LLC
I don't believe that is something that can be recreated using Apex or VF directly. Instead you would just want to use javascript and the onclick event. You can design it to act/look anyway you would like. With a little work you could mirror what salesforce does. The javascript you would want if you were not going to use any libraries would be a confirm box. Instead of including the action directly on the button you would build an <apex:actionFunction> tag and assign it a friendly name and the action you want to call (the one that performs the delete. You can call the actionFunction directly from javascript. 

Check this link out for more info on the actionFunction tag.

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_actionFunction.htm
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
I looked at the page, it was very confusing. I am not too skilled with javascript. What about the apex messages tags, wouldnt they do the trick?
Adnubis LLCAdnubis LLC
The apex message tags are used to display errors on the page. You can either put one tag to display all errors at that section of the page. Or you can do tags if you want to show errors at the field level. What you are looking for is the ability to give the user a chance to opt out of deleting an account. I am going to provide an example here but if you would like more help you can post some code and I will see what I can do. function confirmDelete(){ var confirmedDelete = confirm("Are you sure you want to delete this Opportunity?"); if (r == true){ deleteOpp(); } }
Adnubis LLCAdnubis LLC
So apprently emailing a code block did not work out well. Here is the code I was trying to provide you.

<apex:commandButton value="Delete" onclick="confirmDelete();" />

function confirmDelete(){

  var confirmedDelete = confirm("Are you sure you want to delete this Opportunity?");

  if (r == true){
     deleteOpp();
  }

}

<apex:actionFunction name="deleteOpp" action="{!deleteOpportunity}"/>
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
Thanks James, I will have a play around and see if I can pull it off.
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
Real quick, this is on the page level not the extension/controller level right?
Adnubis LLCAdnubis LLC
Correct. At the bottom of the page right before the ending Body tag you would include a <script>  </script> tag. The function would live inside of the script. The <apex:actionFunction can go above that <script> tag. Also, you will need to wrap the <apex:actionFunction> tag in between <apex:form> tags.
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student

Hey James, I managed to get the box to appear, so thank you for that. So much progress already. But upon clicking ok, the record is not deleted. I have posted my VF page below with all relevant sections highlighted. Thank you for your help.


<apex:page standardController="Account" extensions="AccountExtension,extAccountDel" showHeader="true"
tabStyle="account"  >
<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"/>
<apex:stylesheet value="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/ui-lightness/jquery-ui.css"/>
<script>
$j = jQuery.noConflict();
function highlightElem(elem){
$j(elem).parent().parent().parent().find('tr').removeClass('ui-state-highlight');
$j(elem).parent().parent().addClass('ui-state-highlight');
}

function confirmDelete(){ var confirmedDelete = confirm("Are you sure you want to delete this Fact Finder?"); if (r == true){ deleteFacRecord(); } }
</script>

<style>
.activeTab {background-color: #892034; color:White;
background-image:none}
.inactiveTab { background-color: #00204E; color:white;
background-image:none}
</style>

<style>
input[name=newNote] {
    display: none;
}
input[name=attachFile] {
    display: none;
}

</style>

<apex:tabPanel switchType="client" value="{!BLANKVALUE($CurrentPage.parameters.tab,'AccountDetail')}"
id="AccountTabPanel" tabClass="activeTab"
inactiveTabClass="inactiveTab">
<apex:tab label="Details" name="AccDetails" id="tabdetails" >
<apex:detail inlineEdit="True" relatedList="true" title="true"/>
</apex:tab>
<apex:tab label="Contacts" name="Contacts" id="tabContact">
<apex:pageBlock title="Hello {!$User.FirstName}!">
You are displaying contacts from the {!account.name} account.
Click a contact's name to view his or her details.
</apex:pageBlock>
<apex:pageBlock title="Contacts">
<apex:form >
<apex:dataTable value="{!account.Contacts}" var="contact" cellPadding="4"
border="1">
<apex:column >
<apex:commandLink rerender="detail" oncomplete="highlightElem(this);">
{!contact.Name}
<apex:param name="cid" value="{!contact.id}"/>
</apex:commandLink>
</apex:column>
</apex:dataTable>
</apex:form>
</apex:pageBlock>
<apex:outputPanel id="detail">
<apex:detail subject="{!$CurrentPage.parameters.cid}" relatedList="True" inlineEdit="True"
title="false"/>
</apex:outputPanel>
</apex:tab>

<apex:tab label="Fact Finder" rendered="{!$ObjectType.Fact_Finder__c.Accessible}" name="FactFinder" id="tabFactFinder" >
<apex:pageBlock title="Hello {!$User.FirstName}!">
You are displaying Fact Finders from the {!account.name} account.Click a Fact Finder to view its details.
</apex:pageBlock>
<apex:pageBlock title="Fact Finder" >
<apex:form >
<apex:outputlink value="/a0L/e?CF00N90000007AjAp={!Account.name}&CF00N90000007AjAp_lkid= {!Account.id}">Create New Fact Finder</apex:outputlink>

<apex:pageBlockTable value="{!account.Fact_Finder__r}" var="Fac" cellPadding="4" border="4" >

<!-- Create a column for user to click on delete and delete the record -->
         <apex:column headerValue="Actions" width="50" >
             <!-- Command link allows you to create the value for the link and it allows you to call a action method from your extension -->
             <apex:commandLink value="Delete" onclick="confirmDelete(this);"  action="{!deleteFacRecord}">
            
                 <!-- Paramerer value is to set the parameters being used in your extension then I assigned the parameters in to a string variable in the extension -->
                 <apex:param value="{!Fac.id}" name="deleteRec" assignTo="{!delId }"/>
            
             </apex:commandLink>
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
problem solved simply by adding this to each commandlink:

onclick="if(!confirm('Are you sure?')){return false;}"


Thank you for your help
This was selected as the best answer