+ Start a Discussion
LooseLipsLooseLips 

Adding Campaign Members to Account Page - Controller Issues

 

Hi,

 

I want to check if this is even possible.

 

I have created a stand alone Visuaforce page based on a  custom controller pulling campaign members onto a single page that I want to be visible from the Account page.

 

Of course it seems to link a visualforce page by adding it as a section on the Account page, it needs to be powered by the Account standard controller.

 

Is it possible to write a visualforce page from the standard controller that can get data from as low down as Account>Contact>CampaignMember>Campaign so I can get all my fields?

 

Or alternatively is there a way to put a customer controller powered visualforce page on the Account page? Does the controller need to be 'Account' and add the following class as an extension?

 

I know this is basic stuff but after trawling the internet for an hour I'm alittle stuck.

 

Here's my current code for the stand alone page I have working;

 

public class myCampaignMembers {

 /// Create a list
 /// <OBJECT_NAME>
 List<CampaignMember> rqs;

 /// getReq() - Reffer to the list in the
 /// visualforce page with "Req" minus the "get" from
 /// controller name.
 public List<CampaignMember> getReq() {

  /// Get the data for the list
  rqs = [select id, Campaign.Name, CreatedDate, Contact.ID, Contact.Title, Contact.FirstName, Contact.LastName, Contact.AccountID, Status FROM CampaignMember];
  return  rqs;
 }
}

 

And my Visualforce Page....

 

<apex:page showHeader="false" sidebar="false" controller="myCampaignMembers" tabStyle="Contact">
 <apex:pageBlock title="Campaign Members" id="CamMem">
  <apex:dataTable value="{!Req}" var="CampaignMembers" cellPadding="4" border="1">
   <apex:column >
    <apex:facet name="header">Created Date</apex:facet>
    <apex:outputField value="{!CampaignMembers.CreatedDate}"/>
   </apex:column>
   <apex:column >
    <apex:facet name="header">Campaign Name</apex:facet>
    <apex:outputField value="{!CampaignMembers.Campaign.Name}"/>
   </apex:column>
   <apex:column >
    <apex:facet name="header">Status</apex:facet>
    <apex:outputField value="{!CampaignMembers.Status}"/>
   </apex:column>
      <apex:column >
    <apex:facet name="header">First Name</apex:facet>
    <apex:outputField value="{!CampaignMembers.Contact.FirstName}"/>
   </apex:column>
   <apex:column >
    <apex:facet name="header">Last Name</apex:facet>
    <apex:outputLink value="{!CampaignMembers.Contact.LastName}">{!CampaignMembers.Contact.LastName}</apex:outputLink>
   </apex:column>
   <apex:column >
    <apex:facet name="header">Title</apex:facet>
    <apex:outputField value="{!CampaignMembers.Contact.Title}"/>
   </apex:column>
   <apex:column >
    <apex:facet name="header">Account</apex:facet>
    <apex:outputField value="{!CampaignMembers.Contact.AccountID}"/>
   </apex:column>
  </apex:dataTable>
 </apex:pageBlock>
 
</apex:page>


 

Best Answer chosen by Admin (Salesforce Developers) 
cloudmaniacloudmania

In my opinion there is no way to get the data as low down as Account>Contact>.... without extension class.

 

Your alternative way is the only way:)

 

Inline Vf  like

<apex:page standardController="Account" extensions="MyCampaignMembers">

</apex:page>

But you have to pay ur attention while creating of ur extension class you can get the current account id as a parameter from the constructor then you can query easily.

 

public MyCampaignMembers(ApexPages.StandardController std)

{

Sobject sob=std.getRecord()://HEre is the current record

}

All Answers

cloudmaniacloudmania

In my opinion there is no way to get the data as low down as Account>Contact>.... without extension class.

 

Your alternative way is the only way:)

 

Inline Vf  like

<apex:page standardController="Account" extensions="MyCampaignMembers">

</apex:page>

But you have to pay ur attention while creating of ur extension class you can get the current account id as a parameter from the constructor then you can query easily.

 

public MyCampaignMembers(ApexPages.StandardController std)

{

Sobject sob=std.getRecord()://HEre is the current record

}

This was selected as the best answer
LooseLipsLooseLips

Thanks,

 

I'll give that a go.

 

So it's an extension! Thanks clearng that up.

cloudmaniacloudmania

Could you mark my post as an answer ,if it helped you...Thank you...