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
Veronica CoiinaVeronica Coiina 

How can i order DESC a table filter in contact accountID HELP ME!

i know if i write in my coode this:
SELECT Name, department, phone, gender__c, birthdate FROM contact WHERE AccountID='00136000002JfHw' ORDER BY birthdate desc

this show i want to see but i want to show others contacts asociated with others accounts to.

my code VP
 
<apex:page applyHTMLTag="true" applyBodyTag="false" showHeader="false" renderas="pdf" standardController="Account" extensions="ContactsListController" >
<style type="text/css">
<apex:stylesheet value="{!URLFOR($Resource.style)}"/>
   </style>
<html>
   <body>
        <div style="float: left; ">
         <apex:image alt="cargill" title="cargill"
              url="{!URLFOR($Resource.cargill)}"/>    
     </div> 
        <div style="float: right; ">
    <br/>     
   <apex:outputText value="Caracas,{0,date, dd/MM/yyy}">
       <apex:param value="{!NOW()}" />
                   </apex:outputText><br/>
          {! IF($User.isActive, $User.FirstName & ' ' & $User.LastName,  'inactive') } <br/>
           {! Account.Name }
      
    </div> 
      	<div style="clear:both;"> </div><br/><br/><br/>
           <apex:pageBlock >
               
    <apex:pageBlockTable value="{!Account.contacts}" var="contact">
       
	    <apex:column value="{!contact.Name}"/>
        <apex:column value="{!contact.Department}"/>
        <apex:column value="{!contact.Phone}"/>
        <apex:column value="{!contact.Gender__c}"/> 
        <apex:column value="{!contact.Birthdate}"/>    
        <apex:column >
        <apex:facet name="header">Age</apex:facet>
                        {!year(today())-year(contact.birthdate)- 1}
        </apex:column> 
   
    </apex:pageBlockTable>
          </apex:pageBlock>
     
     
   </body>
</html>       
</apex:page>

and my controller
 
public class ContactsListController 
{   
   	private final Account acct;
    	public ContactsListController(ApexPages.StandardController stdController) {
        this.acct = (Account)stdController.getRecord();
    }       
	public List<Contact> getContacts() 
	{
		List<Contact> results = [SELECT Name, department,phone,gender__c, birthdate FROM contact WHERE account.ID='00136000002JfHw'

                                     ORDER BY birthdate desc]  ;
		return results;
       
	}
}

i think, i need to change anything in my controller but i dont know.
 
Best Answer chosen by Veronica Coiina
Amit Chaudhary 8Amit Chaudhary 8
Please update your class like below :-
public class ContactsListController 
{   
   	public Account acct;
	Public List<Contact> lstCont {get;set;}
   	public ContactsListController(ApexPages.StandardController stdController) 
	{
        this.acct = (Account)stdController.getRecord();
		lstCont = new List<Contact>();
		
		if(acct.id != null)
		{
			lstCont = [ SELECT Name, department,phone,gender__c, birthdate 
										FROM contact 
										WHERE accountid =:acct.id
										ORDER BY birthdate desc
								] ;
		}
    }       
}
VF page like below :-
 
<apex:page applyHTMLTag="true" applyBodyTag="false" showHeader="false" renderas="pdf" standardController="Account" extensions="ContactsListController" >
<style type="text/css">
<apex:stylesheet value="{!URLFOR($Resource.style)}"/>
   </style>
<html>
   <body>
        <div style="float: left; ">
         <apex:image alt="cargill" title="cargill"
              url="{!URLFOR($Resource.cargill)}"/>    
     </div> 
        <div style="float: right; ">
    <br/>     
   <apex:outputText value="Caracas,{0,date, dd/MM/yyy}">
       <apex:param value="{!NOW()}" />
                   </apex:outputText><br/>
          {! IF($User.isActive, $User.FirstName & ' ' & $User.LastName,  'inactive') } <br/>
           {! Account.Name }
      
    </div> 
      	<div style="clear:both;"> </div><br/><br/><br/>
           <apex:pageBlock >
               
    <apex:pageBlockTable value="{!lstCont}" var="contact">
	    <apex:column value="{!contact.Name}"/>
        <apex:column value="{!contact.Department}"/>
        <apex:column value="{!contact.Phone}"/>
        <apex:column value="{!contact.Gender__c}"/> 
        <apex:column value="{!contact.Birthdate}"/>    
        <apex:column >
        <apex:facet name="header">Age</apex:facet>
                        {!year(today())-year(contact.birthdate)- 1}
        </apex:column> 
   
    </apex:pageBlockTable>
          </apex:pageBlock>
     
     
   </body>
</html>       
</apex:page>

NOTE:- Please pass the AccountID in URL like below :-
https:NA.my.salesforce.com/001q000000IzXEf----- ID should be from your org

Please let us know if this will help you

Thanks
Amit Chaudhary
 

All Answers

reymagdaongreymagdaong
Hi Veronica,
line 23.
<apex:pageBlockTable value="{!Account.contacts}" var="contact">

instead of Account.contacts, replace it with contacts which refers to your controller extension.

thanks
Amit Chaudhary 8Amit Chaudhary 8
Please update your class like below :-
public class ContactsListController 
{   
   	public Account acct;
	Public List<Contact> lstCont {get;set;}
   	public ContactsListController(ApexPages.StandardController stdController) 
	{
        this.acct = (Account)stdController.getRecord();
		lstCont = new List<Contact>();
		
		if(acct.id != null)
		{
			lstCont = [ SELECT Name, department,phone,gender__c, birthdate 
										FROM contact 
										WHERE accountid =:acct.id
										ORDER BY birthdate desc
								] ;
		}
    }       
}
VF page like below :-
 
<apex:page applyHTMLTag="true" applyBodyTag="false" showHeader="false" renderas="pdf" standardController="Account" extensions="ContactsListController" >
<style type="text/css">
<apex:stylesheet value="{!URLFOR($Resource.style)}"/>
   </style>
<html>
   <body>
        <div style="float: left; ">
         <apex:image alt="cargill" title="cargill"
              url="{!URLFOR($Resource.cargill)}"/>    
     </div> 
        <div style="float: right; ">
    <br/>     
   <apex:outputText value="Caracas,{0,date, dd/MM/yyy}">
       <apex:param value="{!NOW()}" />
                   </apex:outputText><br/>
          {! IF($User.isActive, $User.FirstName & ' ' & $User.LastName,  'inactive') } <br/>
           {! Account.Name }
      
    </div> 
      	<div style="clear:both;"> </div><br/><br/><br/>
           <apex:pageBlock >
               
    <apex:pageBlockTable value="{!lstCont}" var="contact">
	    <apex:column value="{!contact.Name}"/>
        <apex:column value="{!contact.Department}"/>
        <apex:column value="{!contact.Phone}"/>
        <apex:column value="{!contact.Gender__c}"/> 
        <apex:column value="{!contact.Birthdate}"/>    
        <apex:column >
        <apex:facet name="header">Age</apex:facet>
                        {!year(today())-year(contact.birthdate)- 1}
        </apex:column> 
   
    </apex:pageBlockTable>
          </apex:pageBlock>
     
     
   </body>
</html>       
</apex:page>

NOTE:- Please pass the AccountID in URL like below :-
https:NA.my.salesforce.com/001q000000IzXEf----- ID should be from your org

Please let us know if this will help you

Thanks
Amit Chaudhary
 
This was selected as the best answer
Veronica CoiinaVeronica Coiina
thanks Amit for help me!