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
Barry Taylor SwishCleanBarry Taylor SwishClean 

Using Visualforce pages to display a date specific field?

Hello,

I have what I think is a unique request from the executive management at my organization. They wanted me to build in a sales history displaying a specific account sales history Month to Date as well as display Last Year Month to Date.

This is not a problem and I created the individual fields for the historical sales information and it displays well.

What I woud like to do is create a Visual Force page that will display Month to Date Sales and the directly below I want to display the field that contains Last Year Sales Month to Date so the account managers can see the target or how they did with that account the year previous.

Is there some kind of formula that I can write that says if between April 1 to April 30 display Field April 2013, May 1 to May 30 display May 2013?

This is my current code... it is just  a quick mock up very basic display of blocktables... nothing special.

Any input would be great thanks

<apex:page standardController="Account">
<b>Account Name:{!account.name}</b>
    <apex:pageBlock >
        <apex:pageBlockTable value="{!account}" var="ac">
            <apex:column Value="{!ac.LY_Annual_Sales__c}"/>
            <apex:column value="{!ac.GP__c}"/>        
        </apex:pageBlockTable>
        <apex:pageBlockTable value="{!account}" var="ac">
            <apex:column Value="{!ac.LY_Annual_Sales__c}"/>
            <apex:column value="{!ac.GP__c}"/>        
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>
Best Answer chosen by Barry Taylor SwishClean
nitesh gadkarinitesh gadkari
Hi Barry,

Came up with some different code using SOQL  to help you.showing example with account created in sep 2013 and account created in sept 2014.This may exactly not solve your problem but definitely will give you idea as how to proceed with your problem.you definitely have to code for every month logic.i just hard coded the months.


//VFPage
<apex:page controller="DateIssueController">
  <apex:form >
     <apex:pageBlock >
       <apex:pageBlockSection columns="2">
           
          <apex:pageBlockTable value="{!accountlist}" var="ac">
           
          <apex:column value="{!ac.name}"/>
           <apex:column value="{!ac.createdDate}"/>
       </apex:pageBlockTable>
         <apex:pageBlockTable value="{!accountlist1}" var="ac1">
          <apex:column value="{!ac1.name}"/>
           <apex:column value="{!ac1.createdDate}"/>
       </apex:pageBlockTable>
       </apex:pageBlockSection>
     </apex:pageBlock>
  </apex:form>
</apex:page>

//Controller


public with sharing class DateIssueController {

    public list<account> accountlist { get; set; }
    public list<account> accountlist1 { get; set; }
    
    public DateIssueController(){
    //I will suggest you to write soql query in different method rather then  constructor as i have written    
      this.accountlist =[select id,name,createdDate from account where createdDate >:date.newinstance(2013,9,1) 
      and createdDate <:date.newinstance(2013,9,30) ];
      
      this.accountlist1 =[select id,name,createdDate from account where createdDate >:date.newinstance(2014,9,1) 
      and createdDate <:date.newinstance(2014,9,30) ];
     //for date values you have to code your logic to obtain date range dynamically.  
      }
}


may this code help you a bit.

regards
Nitesh

All Answers

nitesh gadkarinitesh gadkari
Hi Barry,
 You can use Rendered attribute in column tag and check your date values with IF condition  

something like 
<apex:column Value="{!ac.LY_Annual_Sales__c}"  rendered="{!if(date range check,true,false)}"/>
when true it will show the field else not show

Regards
Nitesh


Barry Taylor SwishCleanBarry Taylor SwishClean
Nitesh, Thank you for the comment, I am sure this would work great... one follow up question I am rather new to the SFDC world with these types of configurations how would I enter the date range... specifically the formatting for example Jan 1 to Jan 31 Thanks
nitesh gadkarinitesh gadkari
Hi Barry,

Came up with some different code using SOQL  to help you.showing example with account created in sep 2013 and account created in sept 2014.This may exactly not solve your problem but definitely will give you idea as how to proceed with your problem.you definitely have to code for every month logic.i just hard coded the months.


//VFPage
<apex:page controller="DateIssueController">
  <apex:form >
     <apex:pageBlock >
       <apex:pageBlockSection columns="2">
           
          <apex:pageBlockTable value="{!accountlist}" var="ac">
           
          <apex:column value="{!ac.name}"/>
           <apex:column value="{!ac.createdDate}"/>
       </apex:pageBlockTable>
         <apex:pageBlockTable value="{!accountlist1}" var="ac1">
          <apex:column value="{!ac1.name}"/>
           <apex:column value="{!ac1.createdDate}"/>
       </apex:pageBlockTable>
       </apex:pageBlockSection>
     </apex:pageBlock>
  </apex:form>
</apex:page>

//Controller


public with sharing class DateIssueController {

    public list<account> accountlist { get; set; }
    public list<account> accountlist1 { get; set; }
    
    public DateIssueController(){
    //I will suggest you to write soql query in different method rather then  constructor as i have written    
      this.accountlist =[select id,name,createdDate from account where createdDate >:date.newinstance(2013,9,1) 
      and createdDate <:date.newinstance(2013,9,30) ];
      
      this.accountlist1 =[select id,name,createdDate from account where createdDate >:date.newinstance(2014,9,1) 
      and createdDate <:date.newinstance(2014,9,30) ];
     //for date values you have to code your logic to obtain date range dynamically.  
      }
}


may this code help you a bit.

regards
Nitesh

This was selected as the best answer