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
EzmoEzmo 

Turn SOQL results into links

Hi, I'm not sure if this should be in the Apex or Visualforce section as it spans both.

 

Anyway, I've created a table of results from an SOQL query and I was wondering if it was possible to make it so that the results become links to the records they are representing.

 

I've pasted my controller extension and page code below.

 

Many thanks in advance

 

Eran

 

 

<apex:page standardController="Event_Services_Training__c" extensions="whatsOnExtension" tabstyle="What_s_On__tab">
    <apex:pageblock title="What's On?">
        <apex:pageblocktable var="a" value="{!training}" columns="6">
            <apex:column value="{!a.Title__c}"/>
            <apex:column value="{!a.Venue__c}"/>
            <apex:column value="{!a.Start_Date_of_Event__c}"/>
            <apex:column value="{!a.End_Date_and_Time_of_Event__c}"/>
            <apex:column value="{!a.Places_Remaining__c}"/>
            <apex:column value="{!a.Id}"/>
        </apex:pageblocktable>
    </apex:pageblock>
</apex:page>

 

public class whatsOnExtension{

    public final Event_Services_Training__c training;

    public whatsOnExtension(ApexPages.StandardController stdController) {
        this.training = (Event_Services_Training__c)stdController.getRecord();
    }

    public List<Event_Services_Training__c> trainingQuery = [SELECT Id, Name, title__c, Start_Date_of_Event__c, End_Date_and_Time_of_Event__c, venue__c, places_remaining__c 
                                                            FROM Event_Services_Training__c 
                                                            ORDER BY Start_Date_of_Event__c ASC NULLS FIRST]; 

    public List<Event_Services_Training__c> gettraining(){
        return trainingQuery;
    }

    public void table(){
        for(Event_Services_Training__c t : trainingQuery){
            Event_Services_Training__c tempTraining = new Event_Services_Training__c();
            trainingQuery.add(tempTraining);
        }
    }
}

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

With sobjects its usually just a case of outputting a link to the sobject id:

 

Something like:

 

 

<apex:page standardController="Event_Services_Training__c" extensions="whatsOnExtension" tabstyle="What_s_On__tab">
    <apex:pageblock title="What's On?">
        <apex:pageblocktable var="a" value="{!training}" columns="6">
            <apex:column headerValue="Link">
              <apex:outputLink value="/{!a.Id}">{!a.Name}</apex:outputLink>
            </apex:column>
            <apex:column value="{!a.Title__c}"/>
            <apex:column value="{!a.Venue__c}"/>
            <apex:column value="{!a.Start_Date_of_Event__c}"/>
            <apex:column value="{!a.End_Date_and_Time_of_Event__c}"/>
            <apex:column value="{!a.Places_Remaining__c}"/>
            <apex:column value="{!a.Id}"/>
        </apex:pageblocktable>
    </apex:pageblock>
</apex:page>

 

 

All Answers

bob_buzzardbob_buzzard

With sobjects its usually just a case of outputting a link to the sobject id:

 

Something like:

 

 

<apex:page standardController="Event_Services_Training__c" extensions="whatsOnExtension" tabstyle="What_s_On__tab">
    <apex:pageblock title="What's On?">
        <apex:pageblocktable var="a" value="{!training}" columns="6">
            <apex:column headerValue="Link">
              <apex:outputLink value="/{!a.Id}">{!a.Name}</apex:outputLink>
            </apex:column>
            <apex:column value="{!a.Title__c}"/>
            <apex:column value="{!a.Venue__c}"/>
            <apex:column value="{!a.Start_Date_of_Event__c}"/>
            <apex:column value="{!a.End_Date_and_Time_of_Event__c}"/>
            <apex:column value="{!a.Places_Remaining__c}"/>
            <apex:column value="{!a.Id}"/>
        </apex:pageblocktable>
    </apex:pageblock>
</apex:page>

 

 

This was selected as the best answer
EzmoEzmo

That worked perfectly. Thank you very much bob_buzzard!

 

Typical that it was something so simple :smileytongue:

 

Eran

bob_buzzardbob_buzzard

The beauty of VF and apex - lots of things are simple!