Contents[Hide]

Deleting records with confirmation popup

In code above you can find a extra code which shows how to add delete command link with confiramtion popup.

Visualforce:

<a href="javascript:if (window.confirm('Are you sure?')) DeletePackage('{!package.Id}');" style="font-weight:bold">Del</a>

<apex:actionFunction action="{!doDeletePackage}" name="DeletePackage" reRender="PackagesList" >
    <apex:param name="packageId" value="" assignTo="{!selectedPackageId}"/>
</apex:actionFunction>

Where:
DeletePackage - is a name of function
{!package.Id} - is an ID of record to be deleted
assignTo="{!selectedPackageId}" - pass the value to controller variable.

Controller:

public String selectedPackageId {get; set;}

public PageReference doDeletePackage() {
    Database.Delete(selectedPackageId);
    return null;
}

 

   
© Paweł Woźniak