You need to sign in to do that
Don't have an account?
Alex Makk
Getting related records: Account -> Custom Object
Hi all! I'm really new to apex code, trying to figure out how to get related records from Account. Any help is appreciated!
VF page:
Controller:
Result:
I can't select VF page when setting up a button. My guess is that I need to use Standard controller="Account" and extention (My controller). I'm not sure how to set it correctly. Getting errors.
Also, epudsList is showing related custom object names which is fine, but PageBlockTable will show records not per custom object reocord - but all custom object records together.
So basically I'd like to press button on account and get related records separated. Accoont - > List of custom object records -> (Values related to one record)
Now its showing like: Account -> List of custom object records -> (Values related to multiple records) which is wrong.
Thanks for helping me out!
VF page:
<apex:page Controller="UseofRepeatOnEpudsController"> <apex:form > <apex:pageBlock title="Accounts with assoicated Contacts"> <apex:repeat value="{!epudsList }" var="epd"> <apex:pageBlockSection title="{!epd.name} - {!epd.Account1__r.Name}"> <apex:pageBlockTable value="{!epudsList}" var="epd2"> <apex:column value="{!epd2.Absorbent_drum_1__c}"/> </apex:pageBlockTable> </apex:pageBlockSection> </apex:repeat> </apex:pageBlock> </apex:form> </apex:page>
Controller:
public class UseofRepeatOnEpudsController { public List<Logistic__c> epudsList{get;set;} public List<Account> AccountList{get;set;} public Id accId{get;set;} public UseofRepeatOnEpudsController() { accId = ApexPages.CurrentPage().getparameters().get('Id'); epudsList = new List<Logistic__c>(); epudsList = [SELECT id, Name , Account1__R.Name, Absorbent_drum_1__c From Logistic__c where Account1__c =:accId] ; accountList = [SELECT id, Name From Account]; }
Result:
I can't select VF page when setting up a button. My guess is that I need to use Standard controller="Account" and extention (My controller). I'm not sure how to set it correctly. Getting errors.
Also, epudsList is showing related custom object names which is fine, but PageBlockTable will show records not per custom object reocord - but all custom object records together.
So basically I'd like to press button on account and get related records separated. Accoont - > List of custom object records -> (Values related to one record)
Now its showing like: Account -> List of custom object records -> (Values related to multiple records) which is wrong.
Thanks for helping me out!
Page:
Controller:
If this helped you to resolve your problem then please mark this as best answer so that it can be useful for others. .
Thanks
Sandeep Singhal
But as you see on screenshot, 111 is on every table and many empty rows (empty rows are empty records related to account). 111 should be related to only one related record.
Change the Line 3 of the Controller Code
From To
Hope it Helps....
Best,
Nithesh
Hi Ryan, Is there any reason you are using "Repeat" tag in your visualforce?
I believe thats the reason 111 is appearing on every table. Basically, You are dispalying the same list of records repeatedly.
In a Nut shell, You are using same List (epudsList) in Both Repeat tag and Pageblock table tag.
Okay, lets follow this approach.
Lets Say your Account Object has three related objects ( Object A, Object B, Object C).
So, Your Account ( ABC Inc.) will have related records from these three objects. From what i have understood. You want to display the records in following way...
ABC inc...
Object A
Related Record 1
Related Record 2
Related Record 3
Object B
Related Record 1
Related Record 2
Related Record 3
Object C
Related Record 1
Related Record 2
Related Record 3
So, In Controller we should create three lists for each related Object. Like in the draft psuedo code below...
and The Visualforce format should look like
P.S. This is just a format, You need to make changes accordingly.