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
sumanth kumar 26sumanth kumar 26 

Hyperlink action

Hello Developers...I have a custom object named Products and it is displayed as list. When I click on the name field under list, it should navigate to the detail page and it can be achieved using Hyperlink method. Can anyone suggest how to do that.
Thanks in advance
Sumanth Kumar
Best Answer chosen by sumanth kumar 26
DeveloperSudDeveloperSud
Hi
try this .
<apex:page controller="WorkOrderController" tabstyle="Work_Order__c">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlock title="Work Order Information" mode="edit">
                <apex:pageBlockSection title="Work Order Details">
                    <apex:inputField value="{!workOrder.Account__c}" required="false"/>
                    <apex:inputField value="{!workOrder.Service_Date__c}" required="true"/>
                    <apex:inputField value="{!workOrder.Status__c}" required="true"/>
                </apex:pageBlockSection>
                <apex:pageBlockButtons location="bottom">
                    <apex:commandButton value="Save" action="{!save}"/>
                </apex:pageBlockButtons>
            </apex:pageBlock>
            <apex:pageBlock title="Summary">
                <apex:page controller="WorkOrderController" title="Pie Chart">
                    <apex:chart height="350" width="450" data="{!pieData}">
                        <apex:pieSeries dataField="data" labelField="name"/>
                        <apex:legend position="right"/>
                    </apex:chart>
                </apex:page>
            </apex:pageBlock>
            <apex:pageBlock >            
                <apex:pageBlockSection title="Products">
                    <apex:inlineEditSupport event="ondblClick" 
                                            showOnEdit="saveButton,cancelButton" hideOnEdit="editButton" /> 
                    <apex:pageBlockTable value="{!Products}" var="temp" >
                     
                         <apex:column headerValue="Name"  >
                         <apex:commandlink value="{!temp.Name}" action="{!onclickAction}">
                         <apex:param name="recordId" assignTo="{!recordId}" value="{!temp.id}" />
                         </apex:commandLink>
                         </apex:column>
                         
                        <apex:column value="{!temp.Family__c}" />
                        <apex:column value="{!temp.Measurement_Type__c}" />
                        <apex:column value="{!temp.Cleaning_Unit_Price__c}" />
                        <apex:column value="{!temp.Treatment_Unit_Price__c}" />
                    </apex:pageBlockTable>
                    <apex:pageBlockTable value="{!workOrderItems}" var="temp" >
                        <apex:column value="{!temp.Service__c}" />
                        <apex:column value="{!temp.Quantity__c}" />
                        <apex:column value="{!temp.Length__c}" />
                        <apex:column value="{!temp.Width__c}" />
                    </apex:pageBlockTable>
                    <apex:inputField value="{!productFamily.Family__c}"/>
                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:pageBlock>
    </apex:form>
    
</apex:page>
 
public class WorkOrderController {
    public list<Product2__C> productList {get; set;}
    public Product2__C productFamily {get; set;}
    public Work_Order__C workOrder { get; set; }
    public list<Work_Order_Item__c> workItemList {get; set;}
    public id recordId{get;set;}
    
    
    public WorkOrderController() {
        Id wID = ApexPages.currentPage().getParameters().get('wID');
        workOrder = (wID == null) ? new Work_Order__C() : 
        [SELECT Account__c, Service_Date__c, Status__c FROM Work_Order__C WHERE Id = :wID];
            }
    public void Productlist() {
        Id pID = ApexPages.currentPage().getParameters().get('pID');
        productFamily = (pID == null) ? new Product2__c() : 
        [SELECT Family__c FROM Product2__c WHERE Id = :pID];
            }
    public List<Product2__c> getProducts()
    {
        productList = [select Name,id, Family__c, Measurement_Type__c, Cleaning_Unit_Price__c, Treatment_Unit_Price__c from Product2__c];
        return productList;
    }
    public List<Work_Order_Item__c> getworkOrderItems()
    {
        workItemList = [select Service__c, Quantity__c, Length__c, Width__c from Work_Order_Item__c];
        return workItemList;
    }
    
    
    
    // onclick action method 
    
    public pageReference onclickAction(){
    
    recordId=ApexPages.currentPage().getParameters().get('recordId');
    pageReference pg= new pagereference('/'+recordId);
    pg.setRedirect(true);
    return pg;
     }
    
    public PageReference save() {
        try {
            upsert workOrder;
        } catch(System.DMLException e) {
            
            return null;
        }
        
        PageReference redirectpage = new ApexPages.StandardController(workOrder).view();
        return (redirectpage);

}
      public List<PieWedgeData> getPieData() {
        List<PieWedgeData> data = new List<PieWedgeData>();
        data.add(new PieWedgeData('Bedding', 30));
        data.add(new PieWedgeData('Flooring', 15));
        data.add(new PieWedgeData('Seating', 10));
        data.add(new PieWedgeData('Wall Treatments    ', 20));
        data.add(new PieWedgeData('Other', 20));
        return data;
    }

    // Wrapper class
    public class PieWedgeData {

        public String name { get; set; }
        public Integer data { get; set; }

        public PieWedgeData(String name, Integer data) {
            this.name = name;
            this.data = data;
        }
    }
}


 

All Answers

DeveloperSudDeveloperSud
Hi,

Try the below demo code for your object. Let us know if this works.
<apex:page controller="sample1x">
<apex:form >

<apex:pageBlock >
<apex:pageBlockTable value="{!act}" var="a">
 <apex:column headerValue="Account Name" >
 <apex:commandLink value="{!a.name}" action="{!testAction}">
 <apex:param value="{!a.id}" assignTo="{!recordId}" name="recordid"/>
 </apex:commandLink>
 </apex:column>
</apex:pageBlockTable>
</apex:pageBlock>

</apex:form>
</apex:page>
 
public with sharing class sample1x {

   public List<Account> act{get;set;}
   public id recordId{get;set;}
   public String recordName{get;set;}
   public  sample1x(){
   act=[select name,id from account limit 10];
   }
   
   public pageReference testAction(){
  
   recordid=apexpages.currentpage().getparameters().get('recordId');
   system.debug('******recordId is :*******'+recordId);
   pageReference pg= new pagereference('/'+recordId);
   pg.setRedirect(true);
   
   return pg;
   
   }

}

 
sumanth kumar 26sumanth kumar 26
Thank you Developer Sud for your concern...Below displayed is my code and i want name field form productlist(mentioned in bold) to be hyperlinked to detail page. Can you help me with this requirement.
public class WorkOrderController {
    public list<Product2__C> productList {get; set;}
    public Product2__C productFamily {get; set;}
    public Work_Order__C workOrder { get; set; }
    public list<Work_Order_Item__c> workItemList {get; set;}
    public WorkOrderController() {
        Id wID = ApexPages.currentPage().getParameters().get('wID');
        workOrder = (wID == null) ? new Work_Order__C() : 
        [SELECT Account__c, Service_Date__c, Status__c FROM Work_Order__C WHERE Id = :wID];
            }
    public void Productlist() {
        Id pID = ApexPages.currentPage().getParameters().get('pID');
        productFamily = (pID == null) ? new Product2__c() : 
        [SELECT Family__c FROM Product2__c WHERE Id = :pID];
            }
    public List<Product2__c> getProducts()
    {
        productList = [select Name, Family__c, Measurement_Type__c, Cleaning_Unit_Price__c, Treatment_Unit_Price__c from Product2__c];
        return productList;
    }
    public List<Work_Order_Item__c> getworkOrderItems()
    {
        workItemList = [select Service__c, Quantity__c, Length__c, Width__c from Work_Order_Item__c];
        return workItemList;
    }
    
    public PageReference save() {
        try {
            upsert workOrder;
        } catch(System.DMLException e) {
            
            return null;
        }
        
        PageReference redirectpage = new ApexPages.StandardController(workOrder).view();
        return (redirectpage);

}
      public List<PieWedgeData> getPieData() {
        List<PieWedgeData> data = new List<PieWedgeData>();
        data.add(new PieWedgeData('Bedding', 30));
        data.add(new PieWedgeData('Flooring', 15));
        data.add(new PieWedgeData('Seating', 10));
        data.add(new PieWedgeData('Wall Treatments    ', 20));
        data.add(new PieWedgeData('Other', 20));
        return data;
    }

    // Wrapper class
    public class PieWedgeData {

        public String name { get; set; }
        public Integer data { get; set; }

        public PieWedgeData(String name, Integer data) {
            this.name = name;
            this.data = data;
        }
    }
}




<apex:page controller="WorkOrderController" tabstyle="Work_Order__c">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlock title="Work Order Information" mode="edit">
                <apex:pageBlockSection title="Work Order Details">
                    <apex:inputField value="{!workOrder.Account__c}" required="false"/>
                    <apex:inputField value="{!workOrder.Service_Date__c}" required="true"/>
                    <apex:inputField value="{!workOrder.Status__c}" required="true"/>
                </apex:pageBlockSection>
                <apex:pageBlockButtons location="bottom">
                    <apex:commandButton value="Save" action="{!save}"/>
                </apex:pageBlockButtons>
            </apex:pageBlock>
            <apex:pageBlock title="Summary">
                <apex:page controller="WorkOrderController" title="Pie Chart">
                    <apex:chart height="350" width="450" data="{!pieData}">
                        <apex:pieSeries dataField="data" labelField="name"/>
                        <apex:legend position="right"/>
                    </apex:chart>
                </apex:page>
            </apex:pageBlock>
            <apex:pageBlock >            
                <apex:pageBlockSection title="Products">
                    <apex:inlineEditSupport event="ondblClick" 
                                            showOnEdit="saveButton,cancelButton" hideOnEdit="editButton" /> 
                    <apex:pageBlockTable value="{!Products}" var="temp" > 
                        <apex:column value="{!temp.Name}" />
                        <apex:column value="{!temp.Family__c}" />
                        <apex:column value="{!temp.Measurement_Type__c}" />
                        <apex:column value="{!temp.Cleaning_Unit_Price__c}" />
                        <apex:column value="{!temp.Treatment_Unit_Price__c}" />
                    </apex:pageBlockTable>
                    <apex:pageBlockTable value="{!workOrderItems}" var="temp" >
                        <apex:column value="{!temp.Service__c}" />
                        <apex:column value="{!temp.Quantity__c}" />
                        <apex:column value="{!temp.Length__c}" />
                        <apex:column value="{!temp.Width__c}" />
                    </apex:pageBlockTable>
                    <apex:inputField value="{!productFamily.Family__c}"/>
                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:pageBlock>
    </apex:form>
    
</apex:page>
sumanth kumar 26sumanth kumar 26
Thank you for your answer...But When I click on the record, the page is showing an error "id test 1 must be 15 characters
Error is in expression '{!recordId}' in page test_2".
 Can you help me with this
DeveloperSudDeveloperSud
Hi,

1. Replace the below line like this in vf page 
<apex:param value="{!temp.id}" name="recordId" assignTo="{!recordId}"/>

2.  change the query like this in controller class 
productList = [select Name, id,Family__c, Measurement_Type__c, Cleaning_Unit_Price__c, Treatment_Unit_Price__c from Product2__c];

 
sumanth kumar 26sumanth kumar 26
Its Working now...Can you help me how to put pagination for the above code?
DeveloperSudDeveloperSud
Hi,
Glad to hear it works.
for pagination follow the below link .I found it very helpful.Hope it will help you too.Thanks !!
http://www.redpointcrm.com/add-pagination-to-your-visualforce-pages-using-the-soql-offset-clause
sumanth kumar 26sumanth kumar 26
Hi, sorry to say this but when I click on the record link, it is showing error 
"Formula Expression is required on the action attributes." Can you help me with this?
DeveloperSudDeveloperSud
Hi
try this .
<apex:page controller="WorkOrderController" tabstyle="Work_Order__c">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlock title="Work Order Information" mode="edit">
                <apex:pageBlockSection title="Work Order Details">
                    <apex:inputField value="{!workOrder.Account__c}" required="false"/>
                    <apex:inputField value="{!workOrder.Service_Date__c}" required="true"/>
                    <apex:inputField value="{!workOrder.Status__c}" required="true"/>
                </apex:pageBlockSection>
                <apex:pageBlockButtons location="bottom">
                    <apex:commandButton value="Save" action="{!save}"/>
                </apex:pageBlockButtons>
            </apex:pageBlock>
            <apex:pageBlock title="Summary">
                <apex:page controller="WorkOrderController" title="Pie Chart">
                    <apex:chart height="350" width="450" data="{!pieData}">
                        <apex:pieSeries dataField="data" labelField="name"/>
                        <apex:legend position="right"/>
                    </apex:chart>
                </apex:page>
            </apex:pageBlock>
            <apex:pageBlock >            
                <apex:pageBlockSection title="Products">
                    <apex:inlineEditSupport event="ondblClick" 
                                            showOnEdit="saveButton,cancelButton" hideOnEdit="editButton" /> 
                    <apex:pageBlockTable value="{!Products}" var="temp" >
                     
                         <apex:column headerValue="Name"  >
                         <apex:commandlink value="{!temp.Name}" action="{!onclickAction}">
                         <apex:param name="recordId" assignTo="{!recordId}" value="{!temp.id}" />
                         </apex:commandLink>
                         </apex:column>
                         
                        <apex:column value="{!temp.Family__c}" />
                        <apex:column value="{!temp.Measurement_Type__c}" />
                        <apex:column value="{!temp.Cleaning_Unit_Price__c}" />
                        <apex:column value="{!temp.Treatment_Unit_Price__c}" />
                    </apex:pageBlockTable>
                    <apex:pageBlockTable value="{!workOrderItems}" var="temp" >
                        <apex:column value="{!temp.Service__c}" />
                        <apex:column value="{!temp.Quantity__c}" />
                        <apex:column value="{!temp.Length__c}" />
                        <apex:column value="{!temp.Width__c}" />
                    </apex:pageBlockTable>
                    <apex:inputField value="{!productFamily.Family__c}"/>
                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:pageBlock>
    </apex:form>
    
</apex:page>
 
public class WorkOrderController {
    public list<Product2__C> productList {get; set;}
    public Product2__C productFamily {get; set;}
    public Work_Order__C workOrder { get; set; }
    public list<Work_Order_Item__c> workItemList {get; set;}
    public id recordId{get;set;}
    
    
    public WorkOrderController() {
        Id wID = ApexPages.currentPage().getParameters().get('wID');
        workOrder = (wID == null) ? new Work_Order__C() : 
        [SELECT Account__c, Service_Date__c, Status__c FROM Work_Order__C WHERE Id = :wID];
            }
    public void Productlist() {
        Id pID = ApexPages.currentPage().getParameters().get('pID');
        productFamily = (pID == null) ? new Product2__c() : 
        [SELECT Family__c FROM Product2__c WHERE Id = :pID];
            }
    public List<Product2__c> getProducts()
    {
        productList = [select Name,id, Family__c, Measurement_Type__c, Cleaning_Unit_Price__c, Treatment_Unit_Price__c from Product2__c];
        return productList;
    }
    public List<Work_Order_Item__c> getworkOrderItems()
    {
        workItemList = [select Service__c, Quantity__c, Length__c, Width__c from Work_Order_Item__c];
        return workItemList;
    }
    
    
    
    // onclick action method 
    
    public pageReference onclickAction(){
    
    recordId=ApexPages.currentPage().getParameters().get('recordId');
    pageReference pg= new pagereference('/'+recordId);
    pg.setRedirect(true);
    return pg;
     }
    
    public PageReference save() {
        try {
            upsert workOrder;
        } catch(System.DMLException e) {
            
            return null;
        }
        
        PageReference redirectpage = new ApexPages.StandardController(workOrder).view();
        return (redirectpage);

}
      public List<PieWedgeData> getPieData() {
        List<PieWedgeData> data = new List<PieWedgeData>();
        data.add(new PieWedgeData('Bedding', 30));
        data.add(new PieWedgeData('Flooring', 15));
        data.add(new PieWedgeData('Seating', 10));
        data.add(new PieWedgeData('Wall Treatments    ', 20));
        data.add(new PieWedgeData('Other', 20));
        return data;
    }

    // Wrapper class
    public class PieWedgeData {

        public String name { get; set; }
        public Integer data { get; set; }

        public PieWedgeData(String name, Integer data) {
            this.name = name;
            this.data = data;
        }
    }
}


 
This was selected as the best answer
sumanth kumar 26sumanth kumar 26
Thanks DeveloperSud...This one is Working....Thanks for your Concern... :)