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
nemo nemonemo nemo 

How to use URLFOR with record ID?

I am creating a Visualforce page which displays the list of all account names from the standard Accounts object. I need to be able to list them as URLs so that when clicked they open their respective accounts as a detail page. I am stuck at using the record id in the URLFOR function.

This is what I am trying - 

<apex:page standardController="Account" recordSetVar="accounts">
    <apex:pageBlock title="Account" >
            <apex:repeat value="{! Accounts}" var="a">
                <ul>
                      <!-- <li> <apex:outputField value="{! a.name}"/> </li> 
                      <li> <apex:outputLink value="{! URLFOR($Action.Account.Edit, Account.Id)}"> {! a.name} </apex:outputLink> </li>
                </ul>       
            </apex:repeat>
    </apex:pageBlock>
</apex:page>

I am using $Action.Account.Edit I know that is wrong. I need to be just able to display the account. How do I use the Account Id or the record ID to link this? I spent a lot of time trying this out but not able to figure out. Please help!
Best Answer chosen by nemo nemo
Mahesh DMahesh D
Hi Nemo,

Please use the below code:
 
<apex:page standardController="Account" recordSetVar="accounts">
    <apex:pageBlock title="Account" >
            <apex:repeat value="{! Accounts}" var="a">
                <ul>
                      <!-- <li> <apex:outputField value="{! a.name}"/> </li> 
                      <li> <apex:outputLink value="{! URLFOR($Action.Account.Edit, a.Id)}"> {! a.name} </apex:outputLink> </li>
                </ul>       
            </apex:repeat>
    </apex:pageBlock>
</apex:page>

Please do let me know if it helps you.

Regards,
Mahesh

All Answers

Mahesh DMahesh D
Hi Nemo,

Please use the below code:
 
<apex:page standardController="Account" recordSetVar="accounts">
    <apex:pageBlock title="Account" >
            <apex:repeat value="{! Accounts}" var="a">
                <ul>
                      <!-- <li> <apex:outputField value="{! a.name}"/> </li> 
                      <li> <apex:outputLink value="{! URLFOR($Action.Account.Edit, a.Id)}"> {! a.name} </apex:outputLink> </li>
                </ul>       
            </apex:repeat>
    </apex:pageBlock>
</apex:page>

Please do let me know if it helps you.

Regards,
Mahesh
This was selected as the best answer
nemo nemonemo nemo
That worked Mahesh. Thanks
nemo nemonemo nemo
I am opening this in the Edit Mode. How do I open this in a View Only mode?
Mahesh DMahesh D
Hi Nemo,

Please use below code for view:
 
<apex:page standardController="Account" recordSetVar="accounts">
    <apex:pageBlock title="Account" >
            <apex:repeat value="{! Accounts}" var="a">
                <ul>
                      <!-- <li> <apex:outputField value="{! a.name}"/> </li> -->
                      <li> <apex:outputLink value="{! URLFOR($Action.Account.View, a.Id)}"> {! a.name} </apex:outputLink> </li>
                </ul>       
            </apex:repeat>
    </apex:pageBlock>
</apex:page>

Regards,
Mahesh
nemo nemonemo nemo
I get it. It is View instead of Edit. Thanks