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
VarunCVarunC 

Edit & Delete Command Buttons in Grid View

Hi,

Following is my Code of visualforce for Editing and Deleting a record from Grid iew display of records:

Code:
<apex:commandButton value="Edit" action="{!editContact}">
    <apex:param name="editContact" value="{!c.Id}"></apex:param>
</apex:commandButton>
|&nbsp;
<apex:commandButton value="Del" action="{!removeContact}" onclick="return confirm('Are you sure—');">
    <apex:param name="delContact" value="{!c.Id}"></apex:param>
</apex:commandButton>

and controller class code is as follows:
Code:
        public PageReference removeContact()
        {
                cId = ApexPages.currentPage().getParameters().get('delContact');
                Contact contact = Database.query('select Id from Contact where id='+cId);
                //Contact contact = [select Id from Contact where id=:cId];
                
                delete contact;
                
                return null;
        }

        public PageReference editContact()
        {
  PageReference pageRef= new PageReference('/'+ApexPages.currentPage().getParameters().get('editContact'));
  pageRef.setredirect(true);
  return pageRef;
        }


but when I click Edit or Delete buttons for any record in the list view Nothing happens except that the page refreshes only.

How can I implement Edit and Delete of Records in Visualforce Page display records in Grid View structure?

Thanks.


Sam.arjSam.arj
My suggestion is to set to assignTo attribute of your param tag and read the selected record from the controller property itself.

Code:
<apex:commandButton value="Edit" action="{!editContact}">
    <apex:param name="editContact" value="{!c.Id}" assignTo="{!cParam}"></apex:param>
</apex:commandButton>

 


Code:
instead of:
cId = ApexPages.currentPage().getParameters().get('delContact');

use this:
cId = cParam;


public string cParam
{
  get;
  set;
}


 


VarunCVarunC
It is still not working: I'm receiving URL No Longer Exist Error.

This is my controller Code:
Code:
        public PageReference removeContact()
        {
            Contact contact = [select Id from Contact where id=:cParam];
                
            delete contact;
                
            return null;
        }

        public PageReference editContact()
        {
         PageReference pageRef= new PageReference('/'+cParam);
  pageRef.setredirect(true);
  return pageRef;
        }

 public string cParam
 {
  get;
  set;
 }

 And here is the way I called Edit/Delete from APEX page:
Code:
                            <apex:commandButton value="Edit" action="{!editContact}">
                                <apex:param name="editContact" value="{!c.Id}" assignTo="{!cParam}"></apex:param>
                            </apex:commandButton>
                            |&nbsp;
                            <apex:commandButton value="Del" action="{!removeContact}" onclick="return confirm('Are you sure—');">
                                <apex:param name="delContact" value="{!c.Id}" assignTo="{!cParam}"></apex:param>
                            </apex:commandButton>

 


V MANJUV MANJU
<apex:page controller="scrollupndown" rendered="true">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable var="a" value="{!acclst}" >
                <apex:column headerValue="Delete" >
               
                <apex:commandLink action="{!deleteacc}" onclick="if(!confirm('Are you sure?')) return false;" >
               
                <apex:image value="http://free-121d5f44d20-121d603d1c5-121ee2b8103.force.com/img/func_icons/remove12.gif" width="15" height="15"/>
               
                 <apex:param value="{!a.Id}" name="deleteid" assignTo="{!recid}"/>
                </apex:commandLink>
                </apex:column>
                <apex:column headerValue="Name" >
                <apex:commandLink value="{!a.name}" action="/{!a.id}" target="blank"/>
              
                </apex:column>
               
            </apex:pageBlockTable>
        </apex:pageBlock>
       

    </apex:form>
</apex:page>



public with sharing class scrollupndown {
    public string recid{get;set;}
    public List<Order__c> acclst { get; set; }
    public scrollupndown(){
      acclst = [select name from Order__c];
    }
    public PageReference deleteacc() {
       Order__c ac=[select id,name from Order__c where id=:recid];
       delete ac;
        pagereference ref =new pagereference('/apex/Buttontodelete');
       ref.setredirect(true);
       return ref;
      
    }
}