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
Ram ForceRam Force 

How can i delete a record on click of Delete button?

How can i delete a record on click of Delete button?
 User-added image

Thank you
Jagan
Srinu SomuSrinu Somu
Upon clicking on Delete button please pass the recod id as parameter which you can capture in controller class and perform delete. Please see the below example -
<apex:commandButton value="Delete" action="{!Delete}">
    <apex:param name="accId" value="{!acc.id}"/>
</apex:commandButton>
 
public void delete() {
   Delete ApexPages.currentPage.getParameters().get('accId');
}

Please follow the approach as mentioned above.

Thanks,
Srinu
Deepali KulshresthaDeepali Kulshrestha
Hi Ram,
 
You can use onclick javascript function on commandbutton to open a popup and confirm your delete operation like this:
<apex:commandButton value="Delete" action="{!Delete}" onclick=" return myFunction();/>
   
//Javascript code here

<script>
    function myFunction() {
        var val = confirm(" Do you really want to delete these records);
        if (val == true)
        {
            return true;
        } 
        else
        {
            return false;
        }
    }
</script>
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
Sukanya ChakrabortySukanya Chakraborty
Not working still, can you please help me with the soln??