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
pradyprady 

How can provide link to a record from visualforce page

Hi,

 

I have a VF page which has a list of records. I would like to have a hyperlink on any one field to link to that record.

 

For eg. if the list has a list of opportunities and i would like to point the opportunity name to be hyperlinked to that opportunity record.

 

Thanks

Prady

 

 

 

bob_buzzardbob_buzzard

You can do this via the outputLink component, using the opportunity id.

 

Something like:

 

<apex:outputLink value="/!{opportunity.id}">{!opportunity.Name}</apex:outputLink>

 replace "opportunity" with your var name.

pradyprady

Thanks Bob...

I was wondering how could i use outputlink in this scenario.

 

<apex:repeat var="slot" value="{!liTimeSlots}">

    <tr class="{!IF(ISNULL(slot.sAppointment), 'Free', 'Fill')}">
        <td ><apex:outputText value="{!slot.tstart1}"/></td>

          <td><apex:outputText value="{!IF(ISNULL(slot.sAppointment), 'Free', slot.sAppointment.name)}"/></td>
          <td><apex:outputText value="{!IF(ISNULL(slot.sAppointment), '', slot.sAppointment.Appointment_Type__c)}"/></td>
          <td><apex:outputText value="{!IF(ISNULL(slot.sAppointment), '', slot.sAppointment.Patient__c)}"/></td>
            </tr> 
        <tr >
        <td></td>

          <td><apex:outputText value="{!IF(ISNULL(slot.sAppointmentOverlap), ' ', slot.sAppointmentOverlap.name)}"/></td>
          <td><apex:outputText value="{!IF(ISNULL(slot.sAppointmentOverlap), '', slot.sAppointmentOverlap.Appointment_Type__c)}"/></td>
          <td><apex:outputText value="{!IF(ISNULL(slot.sAppointmentOverlap), '', slot.sAppointmentOverlap.Patient__c)}"/></td>
            </tr>   
</apex:repeat>

 I want to show the link only if slot.sAppointment or  slot.sAppointmentOverlap is not null.

Any idea how to approach this.

 

Thanks

calvin_nrcalvin_nr

Hi Bob and other Visual force gurus,

 

<apex:outputLink value="/!{opportunity.id}">{!opportunity.Name}</apex:outputLink>

 

I am creating 2 pages in VF. One page to display a list of custom object records from a dynamic search. This is complete.

I need to now create a custom VF page to display a single record information when a user clicks on a link on the list page.

 

Assuming I have built the detail page (assume its path is "apex/customDetailPage"), how would I go about creating this link. Because my detail page will need the selected record id passed to it I suppose.

 

Thanks,
Calvin

prady-cmprady-cm

Hi Calvin,

 

You could do this by

<apex:outputLink value="/apex/customDetailPage/?id=!{opportunity.id}">{!opportunity.Name}</apex:outputLink>

 In your controller of the VF page you could capture this id using

ids=date.valueof(ApexPages.currentPage().getParameters().get('id'));

 Now that you have the id you can query the record and assign the values to the VF page fields. there may

be other ways to approach this, but the above method should work.

 

Note: Pls check the syntax as i wrote this on the fly

bob_buzzardbob_buzzard

Its better practice to use the $Page global variable when producing links to other VF pages.  I also tend to use URLFOR to generate the parameters etc.  It doesn't make a huge amount of difference in this case, but its a good habit to get in to:

 

<apex:outputLink value="{!URLFOR($Page.customDetailPage, '', [id=opportunity.id])" />

 

 

calvin_nrcalvin_nr

Thanks a ton Prady and Bob for your replies. I think I should have my answer now and will keep the URLFOR method in mind.

Sivakumari2iSivakumari2i

Hi bob,

 

If i use this, i am redirected to URL No Longer Exists page. Following is my page code.


                       <apex:dataTable value="{!Data}" var="o" id="scoringTable" cellpadding="4" width="100%">
                        <apex:column >
                        <apex:facet name="header">Owner Id</apex:facet>
                           <apex:outputLink value="/!{o.owner_id}">{!o.owner_id}</apex:outputLink>
                        </apex:column>

                        </apex:dataTable>

 

Am i missing anything?

Please help me.

 

Thanks,

S.Sivakumar

bob_buzzardbob_buzzard

Are these records all owned by users, or are any of them owned by queues?  

Sivakumari2iSivakumari2i

If i append the id along with url https://ap1.salesforce.com/ and load it using browser , i am able to get the records.

 

But i cant provide a link to the same record from visualforce page.

 

Thanks,

S.Sivakumar

bob_buzzardbob_buzzard

You have a typo in your merge field:

 

 <apex:outputLink value="/!{o.owner_id}">{!o.owner_id}</apex:outputLink>

 should be :

 

 <apex:outputLink value="/{!o.owner_id}">{!o.owner_id}</apex:outputLink>

 

 

 

Sivakumari2iSivakumari2i

Thanks bob.

 

Its working

 

Regards,

S.Sivakumar

Neha SawantNeha Sawant
Hi Bob,
I am trying to use 

<apex:repeat value="{!ListOpportunity}" var="opp">
            <apex:outputLink value="/<u>{!</u>opp.id}">{!opp.name}</apex:outputLink>
</apex:repeat>


My requirement is In output panel i want to show list of opportunities as link and clicking on that link it should redirect to the detail page.

ListOpportunity - is coming from Apex class.
This page is not build on Opportunity standard controller. It on some different object and apex class takes care of displaying the listOpportunity

Its giving me 
Error: Syntax error. Found '<'

Jesse RoshanJesse Roshan
Hi Neha,

when you are using the below code remove the <u> tags. this would work
            <apex:outputLink value="/{!opp.id}">{!opp.name}</apex:outputLink>
 
Krrish GopalKrrish Gopal
Hi Guys,
How can I use OutputLink to direct to a visualforce page with related list. My VF page shown apex form content only, it will not shown related lists. Please suggest required change in my code
 
VF Page
<apex:page sidebar="false" action="{!CheckSession}"  controller="CaseDetailController" showHeader="false" cache="false" >
    <chatter:feedwithfollowers entityId="{!objcase.Id}"/>
    <apex:form >
        <apex:pageblock mode="maindetail" title="Case Detail">
            <apex:outputpanel >
                <apex:pageblocksection title="Case Information" showheader="true" collapsible="true" columns="2">
                    <apex:outputfield value="{!objcase.CaseNumber}"/>
                    <apex:outputfield value="{!objcase.OwnerId}"/>
                    <apex:outputfield value="{!objcase.Origin}"/>
                    <apex:outputfield value="{!objcase.Priority}"/>
                    <apex:outputfield value="{!objcase.Status}"/>
                    <apex:outputfield value="{!objcase.Stage__c}"/>
                    <apex:outputfield value="{!objcase.Type}"/>
                    <apex:outputfield value="{!objcase.Reason}"/>
                    <apex:outputfield value="{!objcase.CreatedDate}"/>
                    <apex:outputfield value="{!objcase.ClosedDate}"/>
                    <apex:outputfield value="{!objcase.Site__c}"/>
                    <apex:outputfield value="{!objcase.AssetId}"/>
                    <apex:outputfield value="{!objcase.AccountId}"/>
                    <apex:outputfield value="{!objcase.ParentId}"/>
                    <apex:outputfield value="{!objcase.Is_Expenses_Claimed__c}"/>
                </apex:pageblocksection>
                <apex:pageblocksection title="Contact Detail" showheader="true" collapsible="true" columns="2">
                    <apex:outputfield value="{!objcase.ContactId}"/>
                    <apex:outputfield value="{!objcase.Contact.Phone}"/>
                    <apex:outputfield value="{!objcase.Contact.MobilePhone}"/>
                    <apex:outputfield value="{!objcase.Contact.Email}"/>
                    <apex:outputfield value="{!objcase.Contact.Fax}"/>
                </apex:pageblocksection>
                <apex:pageblocksection title="Description Information" showheader="true" collapsible="true" columns="1">
                    <apex:outputfield value="{!objcase.Subject}"/>
                    <apex:outputfield value="{!objcase.Description}"/>
                </apex:pageblocksection>
                <apex:pageblocksection title="Web Information" showheader="true" collapsible="true" columns="2">
                    <apex:outputfield value="{!objcase.SuppliedCompany}"/>
                    <apex:outputfield value="{!objcase.SuppliedEmail}"/>
                    <apex:outputfield value="{!objcase.SuppliedName}"/>
                    <apex:outputfield value="{!objcase.SuppliedPhone}"/>
                </apex:pageblocksection>
                <apex:pageblocksection title="I&C Detail" showheader="true" collapsible="true" columns="2">
                    <apex:outputfield value="{!objcase.P_O_Number_I_C__c}"/>
                    <apex:outputfield value="{!objcase.P_O_Date_I_C__c}"/>
                </apex:pageblocksection>
                <apex:pageblocksection title="Case Assignment" showheader="true" collapsible="true" columns="2">
                    <apex:outputfield value="{!objcase.Service_Center__c}"/>
                    <apex:outputfield value="{!objcase.Engineer_Vendor__c}"/>
                </apex:pageblocksection>
                <apex:pageblocksection title="System Information" showheader="true" collapsible="true" columns="2">
                        <apex:outputfield value="{!objcase.CreatedById}"/>
                        <apex:outputfield value="{!objcase.CreatedDate}" id="createddate" label="Created Date"/>
                        <apex:outputfield value="{!objcase.LastModifiedById}"/>
                        <apex:outputfield value="{!objcase.LastModifiedDate}"/>
                </apex:pageblocksection>
            </apex:outputpanel>
        </apex:pageblock>
    </apex:form>
  
  <!-- ********** Related Lists **********  -->
<apex:outputpanel >
        <apex:relatedList list="OpenActivities" id="openactivities"/>
        <apex:relatedList list="ActivityHistories" id="activityhistories"/>
        <apex:relatedList list="lstAttachment " id="attachments"/>
        <apex:relatedList list="ProcessSteps" />
</apex:outputpanel>
</apex:page>
 
APEX Controller
public class CaseDetailController 
{
   public case objcase{get;set;}
   public CaseDetailController ()
   {    
       
   }
   public pageReference CheckSession()
   {
             objcase = new case();
             objcase = [SELECT AccountId,AssetId,BusinessHoursId,CaseNumber,ClosedDate,CommunityId,ContactId,Contact.Name,Contact.Phone,Contact.MobilePhone,Contact.Email,Contact.Fax,CreatedById,CreatedDate,Created_By__c,CreatorFullPhotoUrl,CreatorName,CreatorSmallPhotoUrl,Description,Engineer_Vendor__c,HasCommentsUnreadByOwner,HasSelfServiceComments,Id,Invoice_Date__c,Invoice_Number__c,IsClosed,IsDeleted,IsEscalated,Is_Expenses_Claimed__c,LastModifiedById,LastModifiedDate,LastReferencedDate,LastViewedDate,Origin,Other_Problem_Reported__c,OwnerId,ParentId,Priority,Problem_Reported__c,P_O_Date_I_C__c,P_O_Number_I_C__c,Reason,Remark__c,Service_Center__c,Site__c,SLAViolation__c,Stage__c,Status,Subject,SuppliedCompany,SuppliedEmail,SuppliedName,SuppliedPhone,SystemModstamp,Type FROM Case where id=:apexpages.currentpage().getparameters().get('id') limit 1];
       return null;
   }
}

 
Jean-Philippe MonetteJean-Philippe Monette
To stick with Visualforce syntax, I would use this approach:
<apex:outputLink value="{!URLFOR($Action.Opportunity.View, opp.Id)}">
  {!opp.Name}
</apex:outputLink>
Malay DesaiMalay Desai
What does the <u> tags does here? I see it removed "/apex" from "/apex/recordId". How does it do that?
Pramod MangalorePramod Mangalore
Finally to answer the original question from @Prady

            <apex:column>
                <apex:outputLink value="/{!URLFOR(opp.Id)}">{!opp.MasterLabel}</apex:outputLink>
            </apex:column>