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
Amol DixitAmol Dixit 

Apply EDIT/DELETE link to each record in pagetable.

Hi,

 

I wants to give EDIT/DELETE link to each record in pagetable. How can I do that?

 

I have tried it with picklist, like I took picklist to select the record and after selection value, applied the edit or delete button.

 

Thank you.

Amol Dixit

kiranmutturukiranmutturu

try this once

page:

<apex:page controller="DataTableEditRemoveController">
<apex:form id="form" >
<apex:pageBlock title="Accounts">
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlockTable value="{!accs}" var="row">
<apex:column >
<apex:outputLink title="" value="/{!row.id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink>&nbsp;|&nbsp;
<a href="javascript&colon;if (window.confirm('Are you sure?')) DeleteAccount('{!row.Id}');" style="font-weight:bold">Del</a>
</apex:column>
<apex:column value="{!row.Name}"/>
<apex:column value="{!row.BillingStreet}"/>
<apex:column value="{!row.BillingCity}"/>
<apex:column value="{!row.BillingPostalCode}"/>
<apex:column value="{!row.BillingCountry}"/>
</apex:pageBlockTable>
</apex:pageBlock>

<apex:actionFunction action="{!DeleteAccount}" name="DeleteAccount" reRender="form" >
<apex:param name="accountid" value="" assignTo="{!SelectedAccountId}"/>
</apex:actionFunction>
</apex:form>
</apex:page>

 

class

 

public class DataTableEditRemoveController {

public List<Account> accs { get; set; }

//used to get a hold of the account record selected for deletion
public string SelectedAccountId { get; set; }

public DataTableEditRemoveController() {
//load account data into our DataTable
LoadData();
}

private void LoadData() {
accs = [Select id, name, BillingStreet, BillingCity, BillingPostalCode, BillingCountry from Account limit 20];
}

public void DeleteAccount()
{
// if for any reason we are missing the reference
if (SelectedAccountId == null) {

return;
}

// find the account record within the collection
Account tobeDeleted = null;
for(Account a : accs)
if (a.Id == SelectedAccountId) {
tobeDeleted = a;
break;
}

//if account record found delete it
if (tobeDeleted != null) {
Delete tobeDeleted;
}

//refresh the data
LoadData();
}


}

SFDC_biSFDC_bi
I tried your code to display a table with edit and delete link, view and edit's are working fine. But, if i click delete button it shows error message. "
Visualforce Error
Help for this Page
The name can only contain underscores and alphanumeric characters. It must begin with a letter and be unique, and must not include spaces, end with an underscore, or contain two consecutive underscores. 


DisplayTable.vfp
<apex:page controller="DataTableEditRemoveController">
<apex:form id="form" >
<apex:pageBlock title="Accounts">
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlockTable value="{!accs}" var="row">
<apex:column >
<apex:outputLink title="" value="/{!row.id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink>&nbsp;|&nbsp;
<a href="javascript&colon;if (window.confirm('Are you sure?')) DeleteAccount('{!row.Id}');" style="font-weight:bold">Del</a>
</apex:column>
<apex:column value="{!row.Name}"/>
<apex:column value="{!row.BillingStreet}"/>
<apex:column value="{!row.BillingCity}"/>
<apex:column value="{!row.BillingPostalCode}"/>
<apex:column value="{!row.BillingCountry}"/>
</apex:pageBlockTable>
</apex:pageBlock>

<apex:actionFunction action="{!DeleteAccount}" name="DeleteAccount" reRender="form" >
<apex:param name="accountid" value="" assignTo="{!SelectedAccountId}"/>
</apex:actionFunction>
</apex:form>
</apex:page>

DataTableEditRemoveController.cls
public class DataTableEditRemoveController {

public List<Account> accs { get; set; }

//used to get a hold of the account record selected for deletion
public string SelectedAccountId { get; set; }

public DataTableEditRemoveController() {
//load account data into our DataTable
LoadData();
}

private void LoadData() {
accs = [Select id, name, BillingStreet, BillingCity, BillingPostalCode, BillingCountry from Account limit 20];
}

public void DeleteAccount()
{
// if for any reason we are missing the reference
if (SelectedAccountId == null) {

return;
}

// find the account record within the collection
Account tobeDeleted = null;
for(Account a : accs)
if (a.Id == SelectedAccountId) {
tobeDeleted = a;
break;
}

//if account record found delete it
if (tobeDeleted != null) {
Delete tobeDeleted;
}

//refresh the data
LoadData();
}


}

Thanks in Advance!!! 
Ankit Sharma 183Ankit Sharma 183
<a href="javascript&colon;if (window.confirm('Are you sure?')) DeleteAccount('{!row.Id}');"style="font-weight:bold">Del</a>
CHANGE YOUR LINK DESCRIPTION & PASS THIS LINK ON THERE. 
 <a href="/apex/taskrecordview?delid={!abc.id}" style="font-weight:bold">Del</a>
CREATE THE VF PAGE THERE CRETE THIS METHOD PASS THE ID OF CURRENT FIELD
Id cid = (Id)ApexPages.currentPage().getParameters().get('delid');
        
        if (cid != null)
        {
            Account acc1 = [select id from Account where id = :cid];
            delete acc1;
            
        }
Sourabh Kumar 41Sourabh Kumar 41

Hi Here is the working code

<apex:page controller="DataTableEditRemoveController">
    <apex:form id="form" >
        <apex:pageBlock title="Accounts">
            <apex:pageMessages ></apex:pageMessages>
            <apex:pageBlockTable value="{!accs}" var="row">
                <apex:column >
                    <apex:outputLink title="" value="/{!row.id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink>&nbsp;|&nbsp;
                    <apex:commandLink action="{!DeleteAccount}" reRender="form" value="Delete">
                        <apex:param name="accountid" value="{!row.Id}" assignTo="{!SelectedAccountId}"/>
                    </apex:commandLink>
                    <!--<a href="javascript&colon;if (window.confirm('Are you sure?')) DeleteAccount('{!row.Id}');" style="font-weight:bold">Del</a>-->
                </apex:column>
                <apex:column value="{!row.Name}"/>
                <apex:column value="{!row.BillingStreet}"/>
                <apex:column value="{!row.BillingCity}"/>
                <apex:column value="{!row.BillingPostalCode}"/>
                <apex:column value="{!row.BillingCountry}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
        <!--
        <apex:actionFunction action="{!DeleteAccount}" name="DeleteAccount" reRender="form" >
            <apex:param name="accountid" value="" assignTo="{!SelectedAccountId}"/>
        </apex:actionFunction>
		-->
    </apex:form>
</apex:page>
 
public class DataTableEditRemoveController {
    
    public List<Account> accs { get; set; }
    
    //used to get a hold of the account record selected for deletion
    public string SelectedAccountId { get; set; }
    
    public DataTableEditRemoveController() {
        //load account data into our DataTable
        LoadData();
    }
    
    private void LoadData() {
        accs = [Select id, name, BillingStreet, BillingCity, BillingPostalCode, BillingCountry from Account limit 20];
    }
    
    public void DeleteAccount()
    {
        System.debug('SelectedAccountId' +SelectedAccountId);
        // if for any reason we are missing the reference
        if (SelectedAccountId == null) {
            
            return;
        }
        
        // find the account record within the collection
        Account tobeDeleted = null;
        for(Account a : accs)
            if (a.Id == SelectedAccountId) {
                tobeDeleted = a;
                break;
            }
        
        //if account record found delete it
        if (tobeDeleted != null) {
            System.debug('Success' +tobeDeleted);
            Delete tobeDeleted;
        }
        
        //refresh the data
        LoadData();
    }
    
    
}