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
Vijay s 16Vijay s 16 

Custom Delete in VF page

Hi Friends,

        I have developed a Custom apex page(Detail page) for Account. I have a button called "Delete". It perform delete as standard delete button.While deleting the record, It need to ask as javascript confirmation whether to delele or cancel. I have acheived through the following code, but only in some cases it is working. Once the record  has been deleted the page has to navigate to the standard "https://cs1.salesforce.com/001/o" account page. Can you please correct me. The details as below


VF Page:
<apex:commandButton onclick="deleteAcc()"  id="deleteButton" value="Delete"/>
 <apex:actionFunction name="deleteAccountRecord" action="{!deleteAccountRecord}" rerender="out" status="myStatus">
             <apex:param name="accID" value="{!Account.Id}"/>
        </apex:actionFunction>

  function deleteAcc()
       {
           var retVal = confirm("Are you sure to delete ?");
           if( retVal == true ){
              deleteAccountRecord();
              return true;
           }else{
              return false;
           }
       }



Controller:
     public PageReference deleteAccountRecord() {
        String accID  = ApexPages.CurrentPage().getParameters().get('accID');
        
        Account accDelete = [SELECT Id From Account where Id = :accID];
        delete accDelete;

        PageReference pageRef = new PageReference(/001/o');
        pageRef.setRedirect(true);
        return pageRef;
        
     }



 
Sagar PareekSagar Pareek
Give try to this instead
 
if(confirm("Are you sure to delete?")){
window.parent.location.href="/apex/accountDelete?Accid={!Account.Id}";
}
This will redirect to a page called - accountDelete ,use your controller with page accountDelete