You need to sign in to do that
Don't have an account?
sfdc fresher
how to print/delete/edit the account record using command link
hi folks,
I just want to navigate to account edit page/print/delete page of the partilcualr record of account of vf page.could anyone please provid me the code.
<apex:column headervalue="Action">
<apex:commandLink action="/{!Account.id}">Edit</apex:commandLink>
<apex:commandLink action="/{!Account.id}">print</apex:commandLink>
<apex:commandLink action="/{!Account.id}">delete</apex:commandLink>
</apex:column
I just want to navigate to account edit page/print/delete page of the partilcualr record of account of vf page.could anyone please provid me the code.
<apex:column headervalue="Action">
<apex:commandLink action="/{!Account.id}">Edit</apex:commandLink>
<apex:commandLink action="/{!Account.id}">print</apex:commandLink>
<apex:commandLink action="/{!Account.id}">delete</apex:commandLink>
</apex:column
Please refer below code snippet. Hope it helps you.
//VF Page
<apex:page controller="RelatedAccountContact" showHeader="false">
<apex:form >
<apex:slds />
<apex:pageBlock id="pbList">
<apex:pageBlockTable value="{!accList}" var="acc" rendered="true">
<apex:column >
<apex:facet name="header">Account Name</apex:facet>
{!acc.Name}
</apex:column>
<apex:column >
<apex:facet name="header">Action</apex:facet>
<apex:commandButton value="Edit" action="{!editAccount}" reRender="pbList">
<apex:param name="SelectedAccountId" value="{!acc.Id}" assignTo="{!SelectedAccountId}"/>
</apex:commandButton>
</apex:column>
<apex:column >
<apex:facet name="header">Action</apex:facet>
<apex:outputlink value="https://ap1.salesforce.com/{!acc.Id}/p?retURL=/{!acc.Id}">Printable View</apex:outputlink>
</apex:commandButton>
</apex:column>
<apex:column >
<apex:facet name="header">Action</apex:facet>
<apex:commandButton value="Delete" action="{!deleteAccount}" reRender="pbList">
<apex:param name="SelectedAccountId" value="{!acc.Id}" assignTo="{!SelectedAccountId}"/>
</apex:commandButton>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
//Apex Class
public class RelatedAccountContact {
public List<Account> accList{get;set;}
public String SelectedAccountId{get;set;}
public RelatedAccountContact()
{
setupAccount();
}
public void setupAccount()
{
accList = new List<Account>();
accList = [SELECT Name,Id FROM Account LIMIT 100];
system.debug(accList);
}
public PageReference editAccount()
{
system.debug('SelectedAccountId Acccount:::'+SelectedAccountId);
//Put your code here
PageReference pageRef = new PageReference('/apex/AccountWithrelatedContact');// Here replace "AccountWithRelatedContact" with your VF page name.
pageRef.setRedirect(true);
return pageRef;
}
public PageReference deleteAccount()
{
system.debug('SelectedAccountId Acccount:::'+SelectedAccountId);
List<Account> accountList = new List<Account>();
accountList = [SELECT Name FROM Account WHERE Id=:SelectedAccountId];
system.debug('AccountList:::'+accountList);
if(accountList.size()>1)
{
delete accountList;
}
PageReference pageRef = new PageReference('/apex/AccountWithrelatedContact');//Here replace "AccountWithRelatedContact" with your VF page name.
pageRef.setRedirect(true);
return pageRef;
}
}
Please select as best answer if it helps you.
Thank You,
Ajay Dubedi