You need to sign in to do that
Don't have an account?
Rajashri
Display Data in single table
Hi,
I have two pageblock table to display the data from two different variables.Can anyone please guide me how can i show the data in single table.
Below is my code
<apex:page StandardController="Campaign" extensions="singleListView">
<apex:form >
<apex:pageBlock mode="maindetail" >
<apex:pageblocktable value="{!CampaignMembers}" var="cm">
<apex:column headerValue="Phone">
<apex:repeat value="{!cm.CampaignMembers}" var="cpm">
<apex:outputfield value="{!cpm.Lead.Phone}" />
</apex:repeat>
</apex:column>
</apex:pageblocktable>
<apex:pageBlockTable value="{!ContactMembers}" var="cmc">
<apex:column headerValue="Phone">
<apex:repeat value="{!cmc.CampaignMembers}" var="cpmc">
<apex:outputfield value="{!cpmc.Contact.Phone}" rendered="{!cpmc.Contact.Phone != null}"/>
</apex:repeat>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
I have two pageblock table to display the data from two different variables.Can anyone please guide me how can i show the data in single table.
Below is my code
<apex:page StandardController="Campaign" extensions="singleListView">
<apex:form >
<apex:pageBlock mode="maindetail" >
<apex:pageblocktable value="{!CampaignMembers}" var="cm">
<apex:column headerValue="Phone">
<apex:repeat value="{!cm.CampaignMembers}" var="cpm">
<apex:outputfield value="{!cpm.Lead.Phone}" />
</apex:repeat>
</apex:column>
</apex:pageblocktable>
<apex:pageBlockTable value="{!ContactMembers}" var="cmc">
<apex:column headerValue="Phone">
<apex:repeat value="{!cmc.CampaignMembers}" var="cpmc">
<apex:outputfield value="{!cpmc.Contact.Phone}" rendered="{!cpmc.Contact.Phone != null}"/>
</apex:repeat>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
All Answers
So, MemberWrappers is a variable of List<MemberWrapper> just like Hope this helps. If yes, mark it as solution so that it can help other's too who have same problem.
It depends on how you want the data to display, really. There are many different ways a pageblock / pageblock section can be rendered. Here's a pretty comprehensive list on the differences of each: http://limitexception.com/2014/03/30/visualforce-a-visual-reference-guide/
If you want a simple pageBlock table with the campaign member and contact data then I would suggest on iterating through all the possible campaign members and printing out the campaign members and contact details in a single row. Below is an example:
Unknown property 'CampaignStandardController.lMemberWrappers'
Can you please help?
My page
<apex:pageBlock mode="maindetail" >
<apex:pageblocktable value="{!lMemberWrappers}" var="mem">
<apex:column headerValue="Phone">
<apex:outputfield value="{!mem.Phone}" />
</apex:column>
</apex:pageblocktable>
Controller Code
public with sharing class singleListView {
public Campaign camp {get; set; }
List<MemberWrapper> lMemberWrappers = new List<MemberWrapper>();
public singleListView(ApexPages.StandardController controller) {
camp = (Campaign)controller.getRecord();
}
public List<Lead> CampaignMembers;
public List<Lead> getCampaignMembers() {
CampaignMembers=[Select Id,Name,(Select id, Campaign.Name,Contact.Phone,Lead.FirstName,Lead.LastName,Lead.Name,LeadID,ContactID,Lead.Phone,Lead.Email, Lastmodifieddate,Status,CampaignId,Campign_ID__c,Lead.MobilePhone From CampaignMembers where CampaignId =:camp.Id and Status != '' ),
(Select Subject, Id,lastModifiedDate From ActivityHistories where lastModifiedDate !=null and Subject !=null order by LastModifiedDate desc limit 1)
From Lead where Id IN(select LeadId from campaignMember where campaignId =:camp.Id ) order by LastModifiedDate desc];
return CampaignMembers;
}
public List<Contact> ContactMembers;
public List<Contact> getContactMembers() {
ContactMembers=[Select Id,Name,(Select id, Campaign.Name,Contact.Phone,Lead.FirstName,Lead.LastName,LeadID,Lead.Name,ContactID,Lead.Phone,Lead.Email,Contact.Email, Lastmodifieddate,Status,CampaignId,Campign_ID__c,Lead.MobilePhone,Contact.MobilePhone From CampaignMembers where CampaignId =:camp.Id and Status != '' ),
(Select Subject, Id,lastModifiedDate From ActivityHistories where lastModifiedDate !=null and Subject !=null order by LastModifiedDate desc limit 1)
From Contact where Id IN(select ContactId from campaignMember where campaignId =:camp.Id ) order by LastModifiedDate desc];
return ContactMembers;
}
public class MemberWrapper {
public String Phone {get; set;}
public MemberWrapper(String Phone) {
this.Phone = Phone;
}
}
}
Content cannot be displayed: SObject row was retrieved via SOQL without querying the requested field: Lead.Phone
Below is my VF page
<apex:page StandardController="Campaign" extensions="singleListView">
<apex:form >
<apex:pageblocktable value="{!lMemberWrappers}" var="mem">
<apex:column headerValue="Phone">
<apex:outputText value="{!mem.Phone}" />
</apex:column>
</apex:pageblocktable>
</apex:pageBlock>
for the highlighted line..
why so?
for(Lead ld : CampaignMembers) {
lMemberWrappers.add(new MemberWrapper(ld.Phone),new MemberWrapper(ld.Name) );
// lMemberWrappers.add(new MemberWrapper(ld.Name));
}
for(Contact con : ContactMembers) {
lMemberWrappers.add(new MemberWrapper(con.Phone),new MemberWrapper(con.Name));
// lMemberWrappers.add(new MemberWrapper(con.Status));
}
public class MemberWrapper {
public String Status {get; set;}
public String Name {get; set;}
public String Phone {get; set;}
public String Mobile {get; set;}
public String LastModifiedDate {get; set;}
public MemberWrapper(String Phone,String Name) {
this.Phone = Phone;
this.Status = Name;
}
PS: Kindly mark appropriate comment as solution which helped you most above.
Campaign Members(Object)..How can we do it?