You need to sign in to do that
Don't have an account?
Vijay 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;
}
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;
}
This will redirect to a page called - accountDelete ,use your controller with page accountDelete