How can I access the value of an apex:repeat element?

305    Asked by AbdulRehman in Salesforce , Asked on May 1, 2023

I have a Visualforce page that generates a comma-separated list of organization (account) IDs. I'd like to pass that list on to a report as a parameter.

In the example below, Organization Member is a junction object that connects Campaign and Account.

I'd like to have a link in the page, something like the following:

Important Report on Accounts in this campaign
Note that this VF page is using the standard controller. I'd prefer a solution that didn't require a controller, but if a controller is necessary, I'll use it.
{!account.Organization__r.id},

Can I get the full comma-separated value out of $Component in one piece or am I going to need to iterate through the individual values of the outputtext elements and gather them up somehow?

Answered by Camellia Kleiber

Doing this in pure Visualforce is ill-advised, mostly because it would need to use an unsupported (not undocumented, but rather, specifically called out in the documentation as unsupported) apex:variable within an apex:repeat.

However, you can easily do this with [removed]

          let organizationIds = []; <apex value="{!Campaign.Organizational_Members__r}" var="account"> organizationIds.push('{!account.Organization__c}'); </apex> [removed](`<a href="/lightning/r/Report/00O1H000007mNBaUAM/view?fv0=${organizationIds.join(',')}">Important Report on Accounts in this campaign</a>`); [removed] </apex>
[removed]

Other constructs are also possible, but this is one of the easiest ways to do this.



Your Answer

Interviews

Parent Categories