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:

 <apex:outputLink value="/lightning/r/Report/00O1H000007mNBaUAM/view?fv0={!<???What goes
 here???>}">Important Report on Accounts in this campaign</apex:outputLink>

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.

<apex:page standardController="Campaign" showHeader="false" sidebar="false" lightningStylesheets="true">

<apex:repeat value="{!Campaign.Organizational_Members__r}" var="account">
<apex:outputtext >{!account.Organization__r.id},</apex:outputText>


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?

1 Answer 1


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 JavaScript:

<apex:page standardController="Campaign" showHeader="false" sidebar="false" lightningStylesheets="true">
        let organizationIds = [];
        <apex:repeat value="{!Campaign.Organizational_Members__r}" var="account">
        document.write(`<a href="/lightning/r/Report/00O1H000007mNBaUAM/view?fv0=${organizationIds.join(',')}">Important Report on Accounts in this campaign</a>`);

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

  • That worked beautifully! The "apex:repeat" inside the script block makes my head spin a bit. It clearly does what it is meant to do, but isn't visible because it's inside that block? I'd like to show the comma-separated so it can be copied for use in other reports, but I can add my original repeat block in for that.
    – Jagular
    Feb 20, 2021 at 20:49
  • 1
    @Jagular Right. We're building a JavaScript block dynamically, so the browser won't show it. You can still use the document.write() bit to output the list directly if you want to (the version we made is hidden inside an anchor/link tag).
    – sfdcfox
    Feb 20, 2021 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.