Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have a requirement to be able to display Financial Year/Weeks/Periods for a number of dates in different objects. In our old Sql system we had a calendar table that was simply a long list of dates along with the FY/Period/Week data and i could just join any date to it as and when. My current thinking is store the same calendar table in custom settings and then create wrapper classes to display the data in VF, however im struggling with this...

As an example i need to display a pageBlockTable showing certain info from the Site object plus the Fiancial Year/Week and Period that the record was added.

So, is the above approach sensible, if so any idea how i should go about it? if not any suggestions of the best way of achieving the desired results?

Thanks for any suggestions. Paul

share|improve this question
    
Do I understand correctly that you had a table with just dates? –  Lex Jan 17 '13 at 11:48
    
the calendar table just had the following fields Date/Financial Year/Week/Period –  paul Jan 17 '13 at 11:52
    
Wouldn't it be better/easier to just use a date object? –  Lex Jan 17 '13 at 12:31

1 Answer 1

up vote 1 down vote accepted

In these situations, if I understand the issue correctly, I usually create an wrapper class that I can use to marry the data together. Within a Controller, I'd do this in an inner class like so...

public Class MyController {

  // this is used for the data table
  public List<MyWrapper> myWrappers {get; set}

  // query and join your objects in the constructor
  public MyController() {

    myWrappers = new List<MyWrapper>();

    MyObject1__c o1 = [SELECT.......];  
    MyObject2__c o2 = [SELECT.......]; 

    MyWrapper wrap = new MyWrapper()
    wrap.obj1 = o1;
    wrap.obj2 = o2; 

    myWrappers.add(wrap);

  }

  public Class MyWrapper {
    public MyObject1__c obj1 {get; set}
    public MyObject2__c obj2 {get; set}
  }

}

For the dates that you are looking to track, I would probably do those in a custom object.

share|improve this answer
    
Essentially im just trying to replicate the following sql query, can i achieve this with the above? –  paul Jan 17 '13 at 16:08
    
SELECT SITES.Site_Ref, SITES.Site_Name, SITES.Date_added, lkp_Calendar.Financial_Year, lkp_Calendar.Period, lkp_Calendar.Week FROM SITES INNER JOIN lkp_Calendar ON SITES.Date_added = lkp_Calendar.Date; –  paul Jan 17 '13 at 16:08
    
Paul, since there is no relationship between those two objects, you can't do a "SOQL Join". It's a limitation of the platform. While not ideal, the solution that I showed above is how most do it. It's essentially a roll-your-own-join approach. –  Kevin O'Hara Jan 17 '13 at 16:21
    
Here are some details on how the SOQL joins work. Note the dependency that the objects be related. wiki.developerforce.com/page/… –  Kevin O'Hara Jan 17 '13 at 16:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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