2

I have a Visualforce table. When a user clicks the value in the cell of this VF table, they are directed to a standard opportunity report. In this report, the Close Date range is for 'Current FY' (Jan 16 to Dec 16) and there are 3 field filters and:

  1. Record Type = always value 'X'
  2. Opportunity Close Date greater or equal to:
  3. Opportunity Close Date less or equal to:

For cell A in the Visualforce table, when the user clicks the value in this cell, they are taken to this standard opportunity report and it all works as expected. The URL for the dynamic report is:

https://[SF instance].com/[report Id]?pv1='1/1/2016'&pv2='1/31/2016'

So, everything is working as expected b/c the second parameter (pv1) is marked as 1st Jan 2016, and the third parameter (pv2) is 31st Jan 2016.

For cell B in the Visualforce table, the same thing happens but the report link instead passes in parameters for between 1st Feb 2016 to 29th Feb 2016.

All this is fine except the fact that this report isn't truly dynamic. Once we are in the year 2017, the report links will all need to be updated from '2016' to '2017' else, once clicked, the report won't return any values. I can't use the current list of date literals, because I'm doing a year to date table month on month, and there are no date literals to filter on a particular month (such as FEBRUARY or MARCH etc).

Can I concatenate a date parameter with a date literal, such that I could do: pv1='1/1{!THIS_YEAR}' to represent 1st Jan 2016? I have tried a few different iterations but to no avail.

How can I make this truly dynamic?

=================================================================================== EDIT to include some of the code as per @sfdcfox suggestion:

<apex:page showHeader="true" sidebar="true" controller="BestSoccerPlayers">

<style type="text/css">

<!-- A LOT OF CSS in here - could reference this in a static resource -->

</style>

<div class="tg-wrap"><table id="tg-tzygj" class="tg">
  <tr>
    <th class="tg-yw42"><b><i><u>[Soccer Club]</u> - [League Level]</i></b></th>
    <th class="tg-yw4l"><b>January</b></th>
  </tr>
  <tr>
    <td class="tg-6k2t"><b><u></u> Real Madrid - La Liga</b></td> 
    <td class="tg-6k2t"><apex:outputText value="{0, number, ###, ### .##}"><apex:param value="{!JanuaryNBYTD}"/><apex:outputLink value="https://cs81.salesforce.com/00O26000000MA16?pv1='1/1/{!currentYear}&pv2='1/31/{!currentYear}"</apex:outputText></td>
</tr></table></div></apex:page>

And then some of the Apex class is:

public without sharing class BestSoccerPlayers{
/*---CONSTANTS---*/
// String SOQL:
 /* Date Values */

    public String getCurrentYear(){
    return (''+System.now().year());
    }     

 public static Double getJanuaryNBYTD() {
        sObject record = Database.Query(soql1 + '1')[0];
        Double amountX = (Double)record.get('amt')==null?0:(Double)record.get('amt');
        return amountX;
    }
  • Where are you building the link? – Adrian Larson Sep 20 '16 at 17:37
  • 2
    Hi Andy. I'd suggest you consider making an edit to add the code that you've tried so far into your question. It'll help get you more refined answers. – sfdcfox Sep 20 '16 at 17:41
3

You can have such dynamic value binding. Just create one variable on controller side as

 public String getCurrentYear(){
   return (''+System.now().year());
 }
 public String getNextYearYear(){
   return (''+(System.now().year()+1));
 }

For one report:

https://[SF instance].com/[report Id]?pv1='1/1/{!currentYear}'&pv2='1/31/{!CurrentYear}'

For other report

https://[SF instance].com/[report Id]?pv1='2/1/{!currentYear}'&pv2='2/29/{!NextYear}'

This way you could introduce dynamic variables in your implementation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.