0

I have a custom object related to Account via look up relationship. For each of the custom object records I would like to display the related AccountHistory.

In theory, I would ideally like to pull 2 lists, Custom Record list and Account history list and then display the records as nested pageblocktable.

Since these 2 objects are not exactly related I am wondering if this is even possible in visual force?

Update

public Class Engagement {


  public Engagement__c[] getDelta(){

   List<Engagement__c> x = [SELECT Name, ID,CreatedDate,Account_ID__c,Delta__c,Account_Name__c,
                      FROM Engagement__c  
                      WHERE (CreatedDate2EqualsToday_1__c = TRUE)
                      ORDER BY Account_ID__c,CreatedDate ASC];

    if(!x.isEmpty())
   {
   for(Integer i=1; i<x.size();i++)
    {
        if(x[i].Account_ID__c == x[i-1].Account_ID__c)
        {
             x[i].Delta__c = x[i].Engagement_Score__c-x[i-1].Engagement_Score__c;                                              
          i++;            
        }     
        else system.debug('nothing found');
    }
    }
  return x;
  }

 Map<id,AccountHistory> mapAccountHistory = new Map<id,AccountHistory>(); 
}

I need to Link result from getDelta() to AccountHistory by using the Account ID field that exists in Engagement__c. I have never used MAPs before so I am really struggling here.

1
  • 1
    Did you try anything at your end, if so post your code Commented Aug 30, 2016 at 22:07

1 Answer 1

0

I'm assuming that you have a custom object, let's say, MyObject__c which has a lookup to Account, let's say, Account__c. AccountHistory object has AccountId field which you can use to map custom records and account history records based on the value in Account__c. You can write a custom Visualforce page + controller to display custom object records with nested AccountHistory records based on the value in Account__c on custom object record.

And, your question 'Since these 2 objects are not exactly related I am wondering if this is even possible in visual force?', it is possible, however, you will need custom Apex code, setup and fill data structure in controller and use couple of apex:repeat or pageBlockTable components to render nested tables.

I have just put together as idea that you may want to proceed with.

Hope this helps.

2
  • Thanks. Does it have be a nested SOQL query or it can be 2 separate lists?
    – Mike
    Commented Aug 31, 2016 at 11:16
  • I think a list of custom object records and a map of account history records with account ids as map keys.
    – jagmohan
    Commented Aug 31, 2016 at 11:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .