• sforcegarrett7
  • NEWBIE
  • 25 Points
  • Member since 2013

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 6
    Replies

Hi all,

 I am trying to clean up my visualforce page so the table displaying my query results aligns better.  What could I use to clean this up so the columns align better?  Thanks in advance for any help!

 

Here is the page:  https://c.na12.content.force.com/servlet/servlet.ImageServer?id=015U0000001KJT8&oid=00DU0000000IYPv&lastMod=1379618932000

*Note...I did remove this image since it was no longer needed after the solution was provided*

 

<apex:page standardController="Contact"  extensions="GenerateTopListResults" >

   <apex:pageBlock mode="maindetail">
        
       <apex:pageBlockTable value="{!CampaignMemberVolunteerList}" var="a" rendered="{!(CampaignMemberVolunteerList.size != 0)}">
            <apex:column value="{!a.Campaign.Name}" headerValue="Most Recent Volunteer Campaign Name"/>
            <apex:column value="{!a.Campaign.Status}" headerValue="Volunteer Campaign Status"/>    
        </apex:pageBlockTable>

        <apex:pageBlockTable value="{!CampaignMemberCommunicationList}" var="b" rendered="{!(CampaignMemberCommunicationList.size != 0)}">
            <apex:column value="{!b.Campaign.Name}" headerValue="Most Recent Communications Campaign"/> 
            <apex:column value="{!b.Campaign.Status}" headerValue="Communication Campaign Status"/>        
        </apex:pageBlockTable>
       
        <apex:pageBlockTable value="{!RelationshipList}" var="c" rendered="{!(RelationshipList.size != 0)}">
            <apex:column value="{!c.Role__c}" headerValue="Most Recent Relationship Role"/>    
            <apex:column value="{!c.Program_Interest__c}" headerValue="Program Interest/Participation"/>     
        </apex:pageBlockTable> 
        
        <apex:pageBlockTable value="{!DocumentationList}" var="d" rendered="{!(DocumentationList.size != 0)}">
            <apex:column value="{!d.Number_of_Repair_Applications__c}" headerValue="Number of Repair Applications"/>        
        </apex:pageBlockTable>
                  
        <apex:pageBlockTable value="{!DonationList}" var="e" rendered="{!(DonationList.size != 0)}">
            <apex:column value="{!e.Opportunity.Name}" headerValue="Donation Name"/>   
            <apex:column value="{!e.Opportunity.CloseDate}" headerValue="Donation Close Date"/>
        </apex:pageBlockTable>    
                                
    </apex:pageBlock>
</apex:page>

Hi all,

 

With the help of my mentor/boss we...mostly he...created the following Apex Class to return the most recent related list record for a Contact:

//========================================================
// Name: GenerateTopListResults
// Type: Class
// Purpose:  This class is used as an Visualforce page extension to retrieve Contact related list items
// Created by: Garrett Farwell and Don Robins
// Created on: Aug 9, 2013
//
// Rev #  Revised on  Revised by        Revision Description
// -----  ----------  -------------------------------------
//  1.0   8/9/2013  Garrett and Don        Initial Release
//=========================================================

public class GenerateTopListResults
{   
       //attribute of the class
       //needs to be private since we are only using it in this class       
       private ID currentContactId;

       //Constructor to get the Contact Id from the Controller Extension
       public GenerateTopListResults(ApexPages.StandardController stdController) {
                 
                 currentContactId = stdController.getId();
        }   

       //A getter method for each list is utilized
       
       //Campaign Members Volunteer List       
       public List<CampaignMember> getCampaignMemberVolunteerList()  {
       
            Return [SELECT Id, Campaign.Name, Campaign.StartDate, Campaign.RecordTypeId FROM CampaignMember WHERE Campaign.RecordTypeID = '012U00000001486' AND ContactId = : currentContactId ORDER BY Campaign.StartDate DESC Limit 1];
        }   
        
        //Campaign Members Communication List 
        public List<CampaignMember> getCampaignMemberCommunicationList()  {
       
            Return [SELECT Id, Campaign.Name, Campaign.StartDate, Campaign.RecordTypeId FROM CampaignMember WHERE Campaign.RecordTypeID = '012U000000014Bo' AND ContactId = : currentContactId ORDER BY Campaign.StartDate DESC Limit 1];
        }           
       
       //RTP Relationship List
       public List<Relationship__c> getRelationshipList()  {
       
            Return [SELECT Start_Date__c, Interest__c,Program_Interest__c,Role__c FROM Relationship__c WHERE Contact__c = : currentContactId ORDER BY Start_Date__c DESC Limit 1];
       }   
       
       //Documentation List
       public List<Documentation__c> getDocumentationList()  {
       
            Return [SELECT Contacts_Documentation__c, Number_of_Applications__c FROM Documentation__c WHERE Contacts_Documentation__c = : currentContactId];
       }       

       //Donation List
       public List<OpportunityContactRole> getDonationList()  {
       
            Return [SELECT ContactId, Role, Opportunity.Name, Opportunity.CloseDate FROM OpportunityContactRole WHERE Role = 'Donor' AND ContactId = : currentContactId AND Opportunity.RecordTypeID <> '012U000000014Wp' AND Opportunity.IsWon = true ORDER BY Opportunity.CloseDate DESC Limit 1];
       }    
 }

 I am using this class as an extension on a visualforce page.  It is just to display the results of the quieries on a Contact record.  I am new to this stuff...how would I write a Test Class to cover the above code?

 

I started to set up the test data but I am not sure if I am doing this correctly.  Even once I have the test data how do I test it properly?  I really appreciate anyone's help!

//========================================================
// Name: GenerateTopListResultsTest
// Type: Test Class
// Purpose: Tests for the GetTopListResultsClass
// Created by: Garrett Farwell
// Created on: August 9th, 2013
//
// Rev #  Revised on  Revised by        Revision Description
// -----  ----------  -------------------------------------
//  1.0   05/10/2013  Garrett Farwell       Initial Release
//=========================================================
@isTest
private class GenerateTopListResultsTest {

    static testMethod void canInsertTestRecords() {
        //=============================================================
        //SETUP
        //=============================================================

        //Create a mock Contact record
        Contact a = new Contact(LastName='Test Contact');
        INSERT a;

        //Create mock Campaign records
        Campaign c1 = new Campaign(Name='TestCommunicationCampaign1', StateDate = '2013-08-09', IsActive = 'true', RecordTypeId = '012U000000014Bo'); 
        Campaign c2 = new Campaign(Name='TestVolunteerCampaign2', StateDate = '2013-02-09', IsActive = 'true', RecordTypeId = '012U00000001486');
        Campaign c3 = new Campaign(Name='TestCommunicationCampaign3', StateDate = '2013-04-09', IsActive = 'true', RecordTypeId = '012U000000014Bo');
        Campaign c4 = new Campaign(Name='TestVolunteerCampaign4', StateDate = '2013-05-09', IsActive = 'true', RecordTypeId = '012U00000001486');
        List<Campaign> campaignList = new List<Campaign> { c1, c2, c3, c4 };
        INSERT campaignList;

		//Create mock CampaignMember records
		CampaignMember cm1 = new CampaignMember(CampaignId=c1.Id, ContactId=a.Id);
		CampaignMember cm2 = new CampaignMember(CampaignId=c2.Id, ContactId=a.Id);
		CampaignMember cm3 = new CampaignMember(CampaignId=c3.Id, ContactId=a.Id);
		CampaignMember cm4 = new CampaignMember(CampaignId=c4.Id, ContactId=a.Id);
		List<CampaignMember> campaignMemberList = new List<CampaignMember> { cm1, cm2, cm3, cm4 };
        INSERT campaignMemberList;

		//Create mock RTP Relationship records
		Relationship__c r1 = new Relationship__c(Contact__c=a.Id, State_Date__c = '2013-06-18');
		Relationship__c r2 = new Relationship__c(Contact__c=a.Id, State_Date__c = '2013-07-15');
		Relationship__c r3 = new Relationship__c(Contact__c=a.Id, State_Date__c = '2013-08-21');
		Relationship__c r4 = new Relationship__c(Contact__c=a.Id, State_Date__c = '2013-02-10');
		List<Relationship__c> rtpRelationshipList = new List<Relationship__c> { r1, r2, r3, r4 };
        INSERT rtpRelationshipList;

		//Create a mock Documentation record
		Documentation__c d1 = new Documentation__c(Contact__c=a.Id)
		INSERT d1;
		
		//Create Repair Application records
		Repair_Application__c ra1 = new Repair_Application__c(Documentation_Reference__c = d1.Id);
		Repair_Application__c ra2 = new Repair_Application__c(Documentation_Reference__c = d1.Id);
		List<Repair_Application__c> repairApplicationList = new List<Repair_Application__c> { ra1, ra2 };
        INSERT repairApplicationList;
        
        //Create Donation/Opportunity records
		Opportunity o1 = new Opportunity(Name= 'TestOpp1', CloseDate = '2013-06-07');
		Opportunity o2 = new Opportunity(Name= 'TestOpp2', CloseDate = '2013-07-15');
		Opportunity o3 = new Opportunity(Name= 'TestOpp3', CloseDate = '2013-08-07');
		List<Opportunity> opportunityList = new List<Opportunity> { o1, o2, o3 };
        INSERT opportunityList;
        
        //Create ContactRole entries
        OpportunityContactRole ocr1 = new OpportunityContactRole(ContactId = a.Id, OpportunityId = o1.Id, Role = 'Donor');
		OpportunityContactRole ocr2 = new OpportunityContactRole(ContactId = a.Id, OpportunityId = o2.Id, Role = 'Donor');
		OpportunityContactRole ocr3 = new OpportunityContactRole(ContactId = a.Id, OpportunityId = o3.Id, Role = 'Donor');
		List<OpportunityContactRole> opportunityContactRoleList = new List<OpportunityContactRole> { ocr1, ocr2, ocr3 };
        INSERT opportunityContactRoleList;
		

        householdIds.add(h.id);

        //Create some mock Opportunities for the household.
        Opportunity o1 = new Opportunity(name='Donation1', StageName = 'Posted', Amount = 500, Household__c = h.id, CloseDate = date.today(), AccountId = a.Id );
        Opportunity o2 = new Opportunity(name='Donation2', StageName = 'Posted', Amount = 750, Household__c = h.id, CloseDate = date.today(), AccountId = a.Id );       
        Opportunity o3 = new Opportunity(name='Donation3', StageName = 'Posted', Amount = 250, Household__c = h.id, CloseDate = date.today(), AccountId = a.Id );
        

 

Hi all,

 

I am wondering if anyone has developed a visualforce page that shows the most "recent" child record in the related list and "rolls it up" on the parent?  I know that can be qualified in many ways but the admiistrator could modify the query to return whatever results make sense.

 

For example...this trigger helps to generate the proper list of records:

http://boards.developerforce.com/t5/Apex-Code-Development/Recent-record-from-related-list/td-p/320385

 

The query in the case of the trigger above is:  [Select Status, LeadId, Id, CreatedDate, ContactId, CampaignId From CampaignMember ORDER BY CreatedDate DESC Limit 5]

 

Taking a step further it would be nice to be able to have a small visualforce page on the parent record to see the returned results rather than having to create a custom field.  I would also like to be able to do this for several objects.  So show me the most recent Campaign the Contact is a member of, show me the most recent closed Opportunity by Close Date, etc.  Sort of like a snapshot on the Contact record instead of having to reference each of the related lists.

 

Sort of like this only backwards:  http://sfdc2u.blogspot.com/2013/05/retrieving-parent-record-from-child.html

https://success.salesforce.com/answers?id=90630000000gpahAAA

 

Any thoughts or ideas appreciated...!

Hi all,

 I am trying to clean up my visualforce page so the table displaying my query results aligns better.  What could I use to clean this up so the columns align better?  Thanks in advance for any help!

 

Here is the page:  https://c.na12.content.force.com/servlet/servlet.ImageServer?id=015U0000001KJT8&oid=00DU0000000IYPv&lastMod=1379618932000

*Note...I did remove this image since it was no longer needed after the solution was provided*

 

<apex:page standardController="Contact"  extensions="GenerateTopListResults" >

   <apex:pageBlock mode="maindetail">
        
       <apex:pageBlockTable value="{!CampaignMemberVolunteerList}" var="a" rendered="{!(CampaignMemberVolunteerList.size != 0)}">
            <apex:column value="{!a.Campaign.Name}" headerValue="Most Recent Volunteer Campaign Name"/>
            <apex:column value="{!a.Campaign.Status}" headerValue="Volunteer Campaign Status"/>    
        </apex:pageBlockTable>

        <apex:pageBlockTable value="{!CampaignMemberCommunicationList}" var="b" rendered="{!(CampaignMemberCommunicationList.size != 0)}">
            <apex:column value="{!b.Campaign.Name}" headerValue="Most Recent Communications Campaign"/> 
            <apex:column value="{!b.Campaign.Status}" headerValue="Communication Campaign Status"/>        
        </apex:pageBlockTable>
       
        <apex:pageBlockTable value="{!RelationshipList}" var="c" rendered="{!(RelationshipList.size != 0)}">
            <apex:column value="{!c.Role__c}" headerValue="Most Recent Relationship Role"/>    
            <apex:column value="{!c.Program_Interest__c}" headerValue="Program Interest/Participation"/>     
        </apex:pageBlockTable> 
        
        <apex:pageBlockTable value="{!DocumentationList}" var="d" rendered="{!(DocumentationList.size != 0)}">
            <apex:column value="{!d.Number_of_Repair_Applications__c}" headerValue="Number of Repair Applications"/>        
        </apex:pageBlockTable>
                  
        <apex:pageBlockTable value="{!DonationList}" var="e" rendered="{!(DonationList.size != 0)}">
            <apex:column value="{!e.Opportunity.Name}" headerValue="Donation Name"/>   
            <apex:column value="{!e.Opportunity.CloseDate}" headerValue="Donation Close Date"/>
        </apex:pageBlockTable>    
                                
    </apex:pageBlock>
</apex:page>

I am just getting started with VF pages, so please forgive me if this is a basic question.

 

I have added an Active (checkbox) object to the contact page. If unchecked, I want the Inactive date to be displayed.

 

I've successfully coded the VF page and added it to my Account page layout. If the contact is active, nothing is displayed. If the contact is not active, the date is displayed.

 

But the alignment is off. While the fields on the standard contact page have their labels right aligned & the data left aligned, the VF page I've added is left aligned.

 

Here's a sample:

 

         Contact Owner  John Doe

                         Name  Sam Smith

         Account Name  ABC Industries

                        Active  (unchecked box)

Inactive Date  09/19/2013

 

 (Sorry...I don't know how to post a picture on the board).

 

Here's the code for the VF page:

 

<apex:page standardController="Contact">

        <apex:form >

            <apex:pageblock id="InactiveDtPageBlock" mode="maindetail">

                <apex:actionregion >

                <apex:pageblocksection columns="1" rendered="{!contact.Active__c == False}">

                    <apex:outputField value="{!Contact.Inactive_Date__c}"/>

                </apex:pageblocksection>

                </apex:actionregion>

            </apex:pageblock>

        </apex:form>

     <script>

        function setFocusOnLoad(){}

     </script>

</apex:page>

 

Is there a way to align the Inactive Date the same as the other fields?

 

Thanks,

Connie

 

  • September 19, 2013
  • Like
  • 0

Hi all,

 

With the help of my mentor/boss we...mostly he...created the following Apex Class to return the most recent related list record for a Contact:

//========================================================
// Name: GenerateTopListResults
// Type: Class
// Purpose:  This class is used as an Visualforce page extension to retrieve Contact related list items
// Created by: Garrett Farwell and Don Robins
// Created on: Aug 9, 2013
//
// Rev #  Revised on  Revised by        Revision Description
// -----  ----------  -------------------------------------
//  1.0   8/9/2013  Garrett and Don        Initial Release
//=========================================================

public class GenerateTopListResults
{   
       //attribute of the class
       //needs to be private since we are only using it in this class       
       private ID currentContactId;

       //Constructor to get the Contact Id from the Controller Extension
       public GenerateTopListResults(ApexPages.StandardController stdController) {
                 
                 currentContactId = stdController.getId();
        }   

       //A getter method for each list is utilized
       
       //Campaign Members Volunteer List       
       public List<CampaignMember> getCampaignMemberVolunteerList()  {
       
            Return [SELECT Id, Campaign.Name, Campaign.StartDate, Campaign.RecordTypeId FROM CampaignMember WHERE Campaign.RecordTypeID = '012U00000001486' AND ContactId = : currentContactId ORDER BY Campaign.StartDate DESC Limit 1];
        }   
        
        //Campaign Members Communication List 
        public List<CampaignMember> getCampaignMemberCommunicationList()  {
       
            Return [SELECT Id, Campaign.Name, Campaign.StartDate, Campaign.RecordTypeId FROM CampaignMember WHERE Campaign.RecordTypeID = '012U000000014Bo' AND ContactId = : currentContactId ORDER BY Campaign.StartDate DESC Limit 1];
        }           
       
       //RTP Relationship List
       public List<Relationship__c> getRelationshipList()  {
       
            Return [SELECT Start_Date__c, Interest__c,Program_Interest__c,Role__c FROM Relationship__c WHERE Contact__c = : currentContactId ORDER BY Start_Date__c DESC Limit 1];
       }   
       
       //Documentation List
       public List<Documentation__c> getDocumentationList()  {
       
            Return [SELECT Contacts_Documentation__c, Number_of_Applications__c FROM Documentation__c WHERE Contacts_Documentation__c = : currentContactId];
       }       

       //Donation List
       public List<OpportunityContactRole> getDonationList()  {
       
            Return [SELECT ContactId, Role, Opportunity.Name, Opportunity.CloseDate FROM OpportunityContactRole WHERE Role = 'Donor' AND ContactId = : currentContactId AND Opportunity.RecordTypeID <> '012U000000014Wp' AND Opportunity.IsWon = true ORDER BY Opportunity.CloseDate DESC Limit 1];
       }    
 }

 I am using this class as an extension on a visualforce page.  It is just to display the results of the quieries on a Contact record.  I am new to this stuff...how would I write a Test Class to cover the above code?

 

I started to set up the test data but I am not sure if I am doing this correctly.  Even once I have the test data how do I test it properly?  I really appreciate anyone's help!

//========================================================
// Name: GenerateTopListResultsTest
// Type: Test Class
// Purpose: Tests for the GetTopListResultsClass
// Created by: Garrett Farwell
// Created on: August 9th, 2013
//
// Rev #  Revised on  Revised by        Revision Description
// -----  ----------  -------------------------------------
//  1.0   05/10/2013  Garrett Farwell       Initial Release
//=========================================================
@isTest
private class GenerateTopListResultsTest {

    static testMethod void canInsertTestRecords() {
        //=============================================================
        //SETUP
        //=============================================================

        //Create a mock Contact record
        Contact a = new Contact(LastName='Test Contact');
        INSERT a;

        //Create mock Campaign records
        Campaign c1 = new Campaign(Name='TestCommunicationCampaign1', StateDate = '2013-08-09', IsActive = 'true', RecordTypeId = '012U000000014Bo'); 
        Campaign c2 = new Campaign(Name='TestVolunteerCampaign2', StateDate = '2013-02-09', IsActive = 'true', RecordTypeId = '012U00000001486');
        Campaign c3 = new Campaign(Name='TestCommunicationCampaign3', StateDate = '2013-04-09', IsActive = 'true', RecordTypeId = '012U000000014Bo');
        Campaign c4 = new Campaign(Name='TestVolunteerCampaign4', StateDate = '2013-05-09', IsActive = 'true', RecordTypeId = '012U00000001486');
        List<Campaign> campaignList = new List<Campaign> { c1, c2, c3, c4 };
        INSERT campaignList;

		//Create mock CampaignMember records
		CampaignMember cm1 = new CampaignMember(CampaignId=c1.Id, ContactId=a.Id);
		CampaignMember cm2 = new CampaignMember(CampaignId=c2.Id, ContactId=a.Id);
		CampaignMember cm3 = new CampaignMember(CampaignId=c3.Id, ContactId=a.Id);
		CampaignMember cm4 = new CampaignMember(CampaignId=c4.Id, ContactId=a.Id);
		List<CampaignMember> campaignMemberList = new List<CampaignMember> { cm1, cm2, cm3, cm4 };
        INSERT campaignMemberList;

		//Create mock RTP Relationship records
		Relationship__c r1 = new Relationship__c(Contact__c=a.Id, State_Date__c = '2013-06-18');
		Relationship__c r2 = new Relationship__c(Contact__c=a.Id, State_Date__c = '2013-07-15');
		Relationship__c r3 = new Relationship__c(Contact__c=a.Id, State_Date__c = '2013-08-21');
		Relationship__c r4 = new Relationship__c(Contact__c=a.Id, State_Date__c = '2013-02-10');
		List<Relationship__c> rtpRelationshipList = new List<Relationship__c> { r1, r2, r3, r4 };
        INSERT rtpRelationshipList;

		//Create a mock Documentation record
		Documentation__c d1 = new Documentation__c(Contact__c=a.Id)
		INSERT d1;
		
		//Create Repair Application records
		Repair_Application__c ra1 = new Repair_Application__c(Documentation_Reference__c = d1.Id);
		Repair_Application__c ra2 = new Repair_Application__c(Documentation_Reference__c = d1.Id);
		List<Repair_Application__c> repairApplicationList = new List<Repair_Application__c> { ra1, ra2 };
        INSERT repairApplicationList;
        
        //Create Donation/Opportunity records
		Opportunity o1 = new Opportunity(Name= 'TestOpp1', CloseDate = '2013-06-07');
		Opportunity o2 = new Opportunity(Name= 'TestOpp2', CloseDate = '2013-07-15');
		Opportunity o3 = new Opportunity(Name= 'TestOpp3', CloseDate = '2013-08-07');
		List<Opportunity> opportunityList = new List<Opportunity> { o1, o2, o3 };
        INSERT opportunityList;
        
        //Create ContactRole entries
        OpportunityContactRole ocr1 = new OpportunityContactRole(ContactId = a.Id, OpportunityId = o1.Id, Role = 'Donor');
		OpportunityContactRole ocr2 = new OpportunityContactRole(ContactId = a.Id, OpportunityId = o2.Id, Role = 'Donor');
		OpportunityContactRole ocr3 = new OpportunityContactRole(ContactId = a.Id, OpportunityId = o3.Id, Role = 'Donor');
		List<OpportunityContactRole> opportunityContactRoleList = new List<OpportunityContactRole> { ocr1, ocr2, ocr3 };
        INSERT opportunityContactRoleList;
		

        householdIds.add(h.id);

        //Create some mock Opportunities for the household.
        Opportunity o1 = new Opportunity(name='Donation1', StageName = 'Posted', Amount = 500, Household__c = h.id, CloseDate = date.today(), AccountId = a.Id );
        Opportunity o2 = new Opportunity(name='Donation2', StageName = 'Posted', Amount = 750, Household__c = h.id, CloseDate = date.today(), AccountId = a.Id );       
        Opportunity o3 = new Opportunity(name='Donation3', StageName = 'Posted', Amount = 250, Household__c = h.id, CloseDate = date.today(), AccountId = a.Id );
        

 

Hi,

          I need to write a trigger to  get most recent record from related list "CampaignMember"  and update to it a custom field on parent "Contact".Any Idea?

Thanks