1. Displaying the account list and click on edit it redirects to edit page.
2. Click on the delete link , it deletes the record and redirect to same page.
2. Click on the delete link , it deletes the record and redirect to same page.
Visualforce Pages:
<apex:page controller="AccountListViewCtr">
<apex:form>
<apex:actionFunction action="{!redirectPage}" name="EditAcc" reRender="form" >
<apex:param name="accountid" value=""/>
</apex:actionFunction>
<apex:actionFunction action="{!deleteAccount}" name="DeleteAccount" reRender="form" >
<apex:param name="accountid2" value=""/>
</apex:actionFunction>
<apex:pageBlock>
<apex:pageBlockTable value="{!lstAccount}" var="acc">
<apex:column value="{!acc.Name}"/>
<apex:column >
<!--<apex:outputLink title="" value="/{!acc.id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink> | -->
<a onclick="EditAcc('{!acc.Id}')" style="font-weight:bold">Edit</a> |
<a onclick="DeleteAccount('{!acc.Id}')" style="font-weight:bold">Del</a>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Class:
public class AccountListViewCtr
{
public List<Account> lstAccount{get;set;}
public AccountListViewCtr()
{
lstAccount=[Select id,name from Account limit 20];
}
public PageReference redirectPage()
{
String accId=ApexPages.currentPage().getParameters().get('accountid');
if(String.isNotBlank(accId))
{
PageReference page=new PageReference('/apex/AccountDetailView?id='+accId);
page.setRedirect(true);
return page;
}
return null;
}
public PageReference deleteAccount()
{
String accId=ApexPages.currentPage().getParameters().get('accountid2');
if(String.isNotBlank(accId))
{
List<Account> acc=[Select id from Account where id=:accId];
if(acc!=null)
{
delete acc;
PageReference page=new PageReference('/apex/AccountView');
page.setRedirect(true);
return page;
}
}
return null;
}
}
Helpfull example
ReplyDelete