Tuesday, March 12, 2013

Displaying the records with Edit, View and Delete Command Links in VF Page


"implementation" Visualforce Page:

<apex:page standardController="Account" recordSetVar="accs" extensions="vedclass">

    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!accs}" var="a">
                <apex:column headerValue="Action">
                    <apex:commandLink value="View" action="{!viewpage}" >
                        <apex:param value="{!a.id}" name="vp" assignTo="{!accid}"/>
                    </apex:commandlink>&nbsp;&nbsp;&nbsp;
                    <apex:commandLink value="Edit" action="{!editpage}">
                        <apex:param value="{!a.id}" name="ep" assignTo="{!accid}"/>
                    </apex:commandlink>&nbsp;&nbsp;&nbsp;
                    <apex:commandLink value="Delete" action="{!del}">
                        <apex:param value="{!a.id}" name="d" assignTo="{!accid}"/>
                    </apex:commandlink>
                </apex:column>
                <apex:column value="{!a.name}"/>
                <apex:column value="{!a.phone}"/>
                <apex:column value="{!a.type}"/>
                <apex:column value="{!a.rating}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex Class:

public with sharing class vedclass {

    public vedclass(ApexPages.StandardsetController controller) {

                                                                                                 }
    public pageReference viewpage(){
           pagereference ref= new pagereference('/apex/viewpage?id='+accid);
        /*pagereference ref=new pagereference('/'+accid);
           if we use above line then no need use of below viewpage VF Page*/
           return ref;
                                                       }
    public pageReference editpage(){
           pagereference ref= new pagereference('/apex/editpage?id='+accid);
        /*pagereference ref=new pagereference('/'+accid);
           if we use above line then no need use of below editpage VF Page*/
            return ref;
                                                     }
    public pageReference del(){
            Account a=[select name from Account where id=:accid];
           delete a;
           pagereference ref=new pagereference('/apex/implementation');
           ref.setredirect(true);
           return ref;
                                           }
    public string accid{get; set;}
                                                 }

"ViewVisualforce Page:
<apex:page standardController="Account" >
 <apex:sectionHeader title="Account"  help="http://www.google.com"/>
  <apex:form >
   <apex:pageBlock title="Account View">
    <apex:PageblockSection title=" Account Information" columns="2" collapsible="true">
        <apex:outputfield value="{!account.Name}"/>
        <apex:outputfield value="{!account.CurrencyIsoCode}"/>
        <apex:outputField value="{!account.phone}"/>
        <apex:outputField value="{!account.rating}"/>
        <apex:outputField value="{!account.result__c}"/>
    </apex:PageblockSection>
    <apex:PageblockSection title="Additional Information" columns="2" collapsible="false">
        <apex:outputfield value="{!account.SLA__c}"/>
        <apex:outputfield value="{!account.SLAExpirationDate__c}"/>
        <apex:outputfield value="{!account.SLASerialNumber__c}"/>  
    </apex:PageblockSection>
    <apex:PageblockButtons location="Bottom">
        <apex:commandButton value="Save" action="{!save}"/>    
        <apex:commandButton value="Cancel" action="{!cancel}"/>  
    </apex:PageblockButtons>
   </apex:pageBlock>
  </apex:form>   
</apex:page>


"Edit" Visualforce Page:

<apex:page standardController="Account" >
 <apex:sectionHeader title="Account"  help="http://www.google.com"/>
  <apex:form >
   <apex:pageBlock title="Account Edit">
    <apex:PageblockSection title=" Account Information" columns="2" collapsible="true">
       <apex:inputField value="{!account.Name}"/>
       <apex:inputField value="{!account.CurrencyIsoCode}"/>
       <apex:inputField value="{!account.phone}"/>
       <apex:inputField value="{!account.rating}"/>
       <apex:inputField value="{!account.result__c}"/>
       </apex:PageblockSection>
    <apex:PageblockSection title="Additional Information" columns="2" collapsible="false">
       <apex:inputfield value="{!account.SLA__c}"/>
       <apex:inputfield value="{!account.SLAExpirationDate__c}"/>
       <apex:inputfield value="{!account.SLASerialNumber__c}"/>  
    </apex:PageblockSection>
    <apex:PageblockButtons location="Bottom">
       <apex:commandButton value="Save" action="{!save}"/>
       <apex:commandButton value="Save&New" action="{!quicksave}"/>
       <apex:commandButton value="Cancel" action="{!cancel}"/>  
    </apex:PageblockButtons>
   </apex:pageBlock>
  </apex:form>  
</apex:page>

No comments:

Post a Comment