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
jdk4702jdk4702 

Pass text clicked to controller method - How do I make a repeated list of clickable Id's?

This should be simple, but I can't figure it out.

 

I have a repeated list of record ID's, and I want to link them all to the respective record, the same way a list view links the Name field to the record.

 

 

<apex:pageBlock>
        <apex:panelgroup >
            <apex:pageblocktable value="{!sRecords}" var="r" >
                <apex:column >
                    <apex:commandLink value="{!r.Id}"  action="{!linkToRecord}">//How do I pass r.Id to the controller method?                                        
                    </apex:commandLink> 
                </apex:column>
            </apex:pageblocktable>
        </apex:panelgroup>
    </apex:pageBlock>

 

public PageReference linkToRecord() {
      String recordId='001A000000P4ZYy';//How do I make this a variable based on the Id clicked?
      PageReference recordPage= new PageReference('/'+recordId);
      return recordPage;
    }

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
sinsiterrulezsinsiterrulez

Hi,

I dont suppose you need a method in controller for it. Try this:

 

<apex:commandLink value="{!r.Name}"  action="/{!r.Id}">

 

 

All Answers

sinsiterrulezsinsiterrulez

Hi,

I dont suppose you need a method in controller for it. Try this:

 

<apex:commandLink value="{!r.Name}"  action="/{!r.Id}">

 

 

This was selected as the best answer
SSRS2SSRS2

You have to use apex param tag and setter getter for assignTo variable.

 

<apex:pageBlock>
        <apex:panelgroup >
            <apex:pageblocktable value="{!sRecords}" var="r" >
                <apex:column >
                    <apex:commandLink value="{!r.Id}"  action="{!linkToRecord}">
			 <apex:param value="{!r.Id}" assignTo="{recordId}"/>
                    </apex:commandLink> 
                </apex:column>
            </apex:pageblocktable>
        </apex:panelgroup>
    </apex:pageBlock>

-

 

//Add following to your class
public string recordId {get; set;}
public PageReference linkToRecord() {
	PageReference recordPage= new PageReference('/'+recordId);
	return recordPage;
}

-Suresh

 

 

jdk4702jdk4702

Thanks both!  I'd love to mark both as the solution, as I used a hybrid.

 

SSR2-I'll use this method for another link I've been struggling with.

 

For this one, I'll use:

 

<apex:commandLink value="View"  action="/{!r.Id}">