0

I am new to Salesforce and Apex in general, and I am trying to figure out how to filter the report charts on a Visual Force page to only show data from opportunities related to the Account record that the user is currently viewing.

As context to the org, we have the standard Account object, and a custom Partner object. The Partner object is the Child, and the Account object is the Parent, with the Partner object being related to the Account object via a lookup field named Partner Account. The page I am trying to add this VF page to is an Account lightning record page layout called Partner Account page.

There are roughly 10 different partner account records in the org. When adding a lightning page report chart component, there is a convenient dropdown that allows me to choose to filter by Partner Account: Account Id, which shows the correct info based on the Partner Account page that the user is currently on. This is the outcome I am trying to achieve in the VF page.

What seems to be making this complicated is that I need to use the Account standard controller in order to put the VF page on the Account page layout, but because the Partner Account: Account Id is a child field, I cannot access the info to limit the data to the right record. I assume I would need to create an extension to access the data from the Partner__c object, but I am having a tough time figuring out how to do that properly.

Here is the code that I have right now for the VF page:

<apex:page standard standardController="Account"> 
<apex:panelGrid columns="2" cellspacing="15">
    <analytics:reportChart reportId="00O35000000nf4QEAQ" size="medium" showRefreshButton="true" filter="[{column:'FK_ACC_ID',operator:'equals',value:'001t000000TbWjP'}]"/>
    <analytics:reportChart reportId="00O35000000nf8iEAA" size="medium" showRefreshButton="true" filter="[{column:'FK_ACC_ID',operator:'equals',value:'001t000000TbWjP'}]"/>
    <analytics:reportChart reportId="00O35000000nfzEEAQ" size="medium" showRefreshButton="true" filter="[{column:'FK_ACC_ID',operator:'equals',value:'001t000000TbWjP'}]"/>
    <analytics:reportChart reportId="00O35000000ngLnEAI" size="medium" showRefreshButton="true" filter="[{column:'FK_ACC_ID',operator:'equals',value:'001t000000TbWjP'}]"/>
    <analytics:reportChart reportId="00O35000000nfurEAA" size="medium" showRefreshButton="true" filter="[{column:'FK_ACC_ID',operator:'equals',value:'001t000000TbWjP'}]"/>
    <analytics:reportChart reportId="00O35000000nfDUEAY" size="medium" showRefreshButton="true" filter="[{column:'FK_ACC_ID',operator:'equals',value:'001t000000TbWjP'}]"/>
    <analytics:reportChart reportId="00O35000000ngLiEAI" size="medium" showRefreshButton="true" filter="[{column:'FK_ACC_ID',operator:'equals',value:'001t000000TbWjP'}]"/>
    <analytics:reportChart reportId="00O35000000nhfNEAQ" size="medium" showRefreshButton="true" filter="[{column:'FK_ACC_ID',operator:'equals',value:'001t000000TbWjP'}]"/>
    <analytics:reportChart reportId="00O35000000nhfhEAA" size="medium" showRefreshButton="true" filter="[{column:'FK_ACC_ID',operator:'equals',value:'001t000000TbWjP'}]"/>
    <analytics:reportChart reportId="00O35000000nhg1EAA" size="medium" showRefreshButton="true" filter="[{column:'FK_ACC_ID',operator:'equals',value:'001t000000TbWjP'}]"/>     
    <analytics:reportChart reportId="00O35000000nhfrEAA" size="medium" showRefreshButton="true" filter="[{column:'FK_ACC_ID',operator:'equals',value:'001t000000TbWjP'}]"/>
    <analytics:reportChart reportId="00O35000000nfz9EAA" size="medium" showRefreshButton="true" filter="[{column:'FK_ACC_ID',operator:'equals',value:'001t000000TbWjP'}]"/>
    <analytics:reportChart reportId="00O35000000nhWiEAI" size="medium" showRefreshButton="true" filter="[{column:'FK_ACC_ID',operator:'equals',value:'001t000000TbWjP'}]"/>
    <analytics:reportChart reportId="00O35000000nhWdEAI" size="medium" showRefreshButton="true" filter="[{column:'FK_ACC_ID',operator:'equals',value:'001t000000TbWjP'}]"/>     
</apex:panelGrid>
</apex:page>

The column, FK_ACC_ID, is the name in the metadata for the Partner Account: Account Id column in the report. For now, I have the value 001t000000TbWjP hardcoded to point to a specific Partner Account. However, I cannot figure out how to get this to be dynamic. I have tried creating an extension controller in multiple different ways, using a query to lookup the specific info I am looking for. But I am struggling to understand how to implement it on the VF page properly. In these cases I have add the extensions tag to the above code.

Here is the latest extension controller I tried using:

public class PartnerCustomControllerTest {

public PartnerCustomControllerTest(ApexPages.StandardController sc) {
    
    Partner__c p = [SELECT Partner_Account__r.Id FROM Partner__c WHERE Partner_Account__r.Id = :ApexPages.currentPage().getParameters().get('Partner_Account__r.Id')]; 
        
}
}

My understanding of how this all works is super rough right now, so I'm sure this extension looks pretty bad, but any advice or direction on how I should approach this would be much appreciated!

Your Answer

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

Browse other questions tagged or ask your own question.