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
newbiewvfdevnewbiewvfdev 

How to show selected Campaign's Campaign Members.

Hi there,

 

I have a list of dataTable with Campaigns with a select button for each row. When the user clicks the select button I would like to show the CampaignMembers(Contacts and Leads) in the bottom of the page in another page block.  I know in salesforce if you go to the Campaign record it shows the CampaignMembers in the related list.  Is there a control in visualforce that I can use do this or do I need to manually implement this? Please let me know which way I should start. Thank You.

 

newbie

Best Answer chosen by Admin (Salesforce Developers) 
jkucerajkucera

Turns out I didn't check it with a CampaignID.  It's a salesforce bug and I've asked my team to work on a fix.  Sorry for the inconvenience-I'm surprised this issue hasn't come up before.

 

That means for the next few weeks related list isn't an option, but the data table approach may still work. 

 

To stay on top of progress for the bug fix, the best way is to log a case with support & have them track against this link:

https://gus.soma.salesforce.com/a0790000000DN5uAAG

 

You won't be able to open the link, but support will. 

All Answers

jkucerajkucera

Related list tag should do the trick as long as you pass the campaign ID to the page using a controller extension or page reference.

 

Search for related list here:

http://www.salesforce.com/us/developer/docs/pages/index.htm

 

<apex:Page standardController="Campaign">
<apex:relatedlist list ="CampaignMembers" />
</apex:page>

 

Note there aren't list controllers on CampaignMember as there aren't list views on CampaignMember.

newbiewvfdevnewbiewvfdev

Hi there,

 

I am not sure what you meant by pass the campaign id to the page using controller extension or page reference. Would you be able to give a sample code. This is what I have so far:

 

<apex:page Controller="campaignController">

<apex:form >

        <apex:pageBlock >

<apex:dataTable value="{!CampaignRecords}" var="campaign" styleClass="list">

<apex:column >

<apex:facet name="header">Campaign Name</apex:facet>

<apex:outputText value="{!campaign.Name}"/>

</apex:column>

<apex:column >

<apex:facet name="header">Action</apex:facet>

<apex:commandLink value="Select" action="{!pullCampaignMembers}" styleClass="btn">

<apex:param name="campaignId" value="{!campaign.Id}" />

</apex:commandLink>

</apex:column>

</apex:dataTable>

</apex:pageBlock>

</apex:form>

<apex:relatedList list="CampaignMembers" subject="{!campaign.Id}" />

</apex:page>

 

I am showing all the Campaigns on the top of the page.  Each row has a select button. When the user selects a button, I want to show the CampaignMembers on the bottom and that's where I am having trouble.

newbiewvfdevnewbiewvfdev

Hi there,

 

now, I am getting this message when I select a campaign: 'CampaignMembers' is not a valid child relationship name for entity Campaign.

 

Does anyone know how we can fix this? Thanks.

 

 

jkucerajkucera

Given you aren't using a Campaign standard controller, I don't think the CampaignMember related list approach will work.

 

You may be able to use a 2nd data table with the campaign member results (or is that where you had problems initially?).  

 

For the table, the approach I would use is a partial page refresh that gets the selected CampaignId and populates a campaign member table. Here's an example from my Lead Scoring app on the AppExchange:

 btw-if you use the code tag, you avoid the smiley face issue when posting & it's easier to debug as then I can copy & paste to test.

<apex:pageBlock title="Lead Scoring Rule Detail" id="thePageBlock"> <apex:pageBlockSection > <apex:inputField value="{!LeadScoringRule__c.Type__c}" > <apex:actionSupport event="onchange" rerender="thePageBlock"/> </apex:inputField> </apex:pageBlockSection > <apex:pageBlockSection > <apex:inputField id="camp" value="{!LeadScoringRule__c.Campaign__c}" rendered="{!LeadScoringRule__c.Type__c=='Campaign Member'}" /> </apex:pageBlockSection> </apex:PageBlock>

 

newbiewvfdevnewbiewvfdev

Hi John,

 

Thank you very much for your reply.  If I did use dataTable to implement it, but I did not use partial page refresh, I will look into that soon.  Also, I am wondering if I use the standard controller for campaign, would it work? I just tried this code. But it's complaining 'CampaignMembers' is not a valid child relationship name for entity Campaign

<apex:page standardcontroller="Campaign"> <apex:relatedList list="CampaignMembers"/> </apex:page>

 

If I could use the Standard Controller to access the relatedList, I would like to ignore the dataTable approach. That is if I could specify another extension for the existing functionality that I have in the controller.

jkucerajkucera

That's strange - I didn't get that error for the related list using your snippet below. What API version are you using for the VF page?

 

If you use the Campaign standard controller, it may be trickier to get the datatable of campaigns to show (but maybe not).

newbiewvfdevnewbiewvfdev

Hi John,

 

I am using Version 17.0 for my Visual Force page.  I tried changing the Version to 16.0 and 15.0 and it still saying it's not a valid child relationship name.

 

This is the URL that I am using the access the page. https://c.na3.visual.force.com/apex/HelloWorld?id=70150000000CvxN

 

 

The Id that I am passing in is an id of a Campaign.  Are you using exactly the same code that I pasted before?

jkucerajkucera

Turns out I didn't check it with a CampaignID.  It's a salesforce bug and I've asked my team to work on a fix.  Sorry for the inconvenience-I'm surprised this issue hasn't come up before.

 

That means for the next few weeks related list isn't an option, but the data table approach may still work. 

 

To stay on top of progress for the bug fix, the best way is to log a case with support & have them track against this link:

https://gus.soma.salesforce.com/a0790000000DN5uAAG

 

You won't be able to open the link, but support will. 

This was selected as the best answer
newbiewvfdevnewbiewvfdev

Hi John,

 

Thank you for all your replies. I logged a bug, hopefully it will fixed sooner than later. Thanks.