0

I've been struggling with creating code (I am not a developer) for a VP where all Campaign Members with certain fields completed (CampaignMember.Article_Link__c) are displayed in a table.

The goal is to have this information display for each company the campaign is for. The table shows up fine, but I can't figure out how to query the information correctly. Searching other people's code and trying to adapt for my needs isn't working; I always get a "illegal from list to list" error.

Apex

<apex:page standardController="Campaign" extensions="CampaignMembers">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!CampaignMember}" var="member">
<apex:column headerValue="Date">
<apex:outputfield value="{!CampaignMember.FirstRespondedDate}"/>
</apex:column>

<apex:column headerValue="Source">
<apex:outputfield value="{!CampaignMember.Source__c}"/>
</apex:column>

<apex:column headerValue="Outlet">
<apex:outputfield value="{!CampaignMember.CompanyOrAccount}"/>
</apex:column>

<apex:column headerValue="Placement">
<apex:outputfield value="{!CampaignMember.Article_Link__c}"/>
</apex:column>
    
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
 
</apex:page>

Class

public with sharing class CampaignRelatedListExtension
{
    public List<CampaignMember> campaignMembers { get; set; }
    public List<Campaign> Campaign { get; set; }
    public CampaignRelatedListExtension(ApexPages.StandardController controller)
    {
        CampaignMembers = [
            SELECT CampaignMember.FirstRespondedDate, CampaignMember.Source__c, CampaignMember.CompanyorAccount, CampaignMember.Article_Link__c FROM CampaignMember
        ];  
}
 }  

Apex that works: enter image description here

Goal: Tab: Company #1: date, source, outlet, link (20 records) Tab: Company #2: date, source, outlet, link (10 different records), etc.

1

You have a few issues with the VF page:

<apex:page standardController="Campaign" extensions="CampaignMembers">
  <apex:form >
    <apex:pageBlock >
      <apex:pageBlockTable value="{!CampaignMember}" var="member">
         <apex:column headerValue="Date">
            <apex:outputfield value="{!CampaignMember.FirstRespondedDate}"/>
         </apex:column>

         ...

       </apex:pageBlockTable>
    </apex:pageBlock>
  </apex:form>

</apex:page>
  1. The extensions attribute must reference the classname of the extensions, hence it should be:

    <apex:page standardController="Campaign" extensions="CampaignRelatedListExtension">
    
  2. The pageBlockTable value property must refer to a collection in the Controller so it should be

    <apex:pageBlockTable value="{!campaignMembers}" var="member">

  3. The columns need to reference the pageBlocvkTable var attribute so they should look like:

    <apex:column headerValue="Date">
        <apex:outputfield value="{!member.FirstRespondedDate}"/>
     </apex:column>
    
  4. The query you have in the controller fetches all possible CampaignMembers as you don't have a WHERE clause:

    public CampaignRelatedListExtension(ApexPages.StandardController controller)
     {
       CampaignMembers = [
        SELECT CampaignMember.FirstRespondedDate, CampaignMember.Source__c, CampaignMember.CompanyorAccount, CampaignMember.Article_Link__c 
        FROM CampaignMember
       ];  
      }
    

It is not exactly clear from your question what your WHERE clause should be but if you are looking for only CampaignMembers where Article_Link__c is non null then you would do:

SELECT CampaignMember.FirstRespondedDate, CampaignMember.Source__c, CampaignMember.CompanyorAccount, CampaignMember.Article_Link__c 
FROM CampaignMember
WHERE Article_Link__c != NULL 
1
  • OH MY GOODNESS, thank you so much! I cannot express to you the importance of your assistance, and truly breaking down where the issues were. You helped a ton (over a week of trying to figure it out on my own) and I've also learned a lot. Thank you, thank you, thank you! – ABFoC Apr 12 at 13:33

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.