You need to sign in to do that
Don't have an account?
CodenameSnugs
Custom Related List Problem
I have a custom related list showing on Accounts that lists the account's discounts. This works fine, however sometimes an account won't have any discount to show as the discount are loaded against the parent account.
I was wondering if it is possible to create another related list to show the parent account's discounts, but show it on the child account so they can see both discounts and parent account discounts?
Any help would be appreciated!
You are pretty close. :) Hang in there.
So, from what I read in the documentation not all the fields of the account are readily available. See here: http://www.salesforce.com/us/developer/docs/pages/Content/apex_pages_standardcontroller.htm
"Note that only the fields that are referenced in the associated Visualforce markup are available for querying on this SObject. All other fields, including fields from any related objects, must be queried using a SOQL expression."
So you'll need to query all the necessary fields in the constructor.
What do you mean "make the VF page span both columns on the account page layout"? Check the layout section options(the wrench in the right corner) to see if you cannot modify it from there(I might be wrong cause I don't really know your problem).
Have a nice day,
Adrian
All Answers
Hello,
How are you displaying the related list? Are you using or custom code in the controller to retrieve the records?
To show the Parent Account related Discounts you should use a custom controller and vf page.
Adrian
Can a VF page be shown within a page layout?
Sure... Enter a layout to edit it and you'll see a VisualForce pages section.
The only limitation is (I hope I'm not wrong) that the page needs to have the standardcontroller of the same object. Otherwise it will not show up on the layout edit list.
Adrian
That would make sense.....so I would basically need to use the standard controller for accounts on the VF page. But can I add methods into the standard controllers? I would need a method to query back all discounts and somehow pass the accounts parent account field into the query to pull back the correct discounts?
You'll have an apex:page like this:
You'll need an apex class MyController where you'll get the list of related records for the parent Account.
See here how to do it:
http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_extension.htm
Adrian
OK...sorry about the dumb questions but 'm pretty new to salesForce and a only just starting to look a apex.
In the extension how would I reference the parent account field within the account page for use in the SOQL query?
There are no dumb questions :) (just answers... ).
So, you have access to the Account record through the acct = (Account)stdController.getRecord(); piece of code from teh controller (check out the example from the previous link that I gave you). When you extract that list for the related records just use "WHERE Account__c =:acct.ParentId"; replace Account__c with the name of your custom lookup relationship.
Ok so I found some code and modified it for the controller extension, does this look right?
I should be able to reference {!searchResults} to get the results from the standard controller, but I think I need to trigger the search() function somehow first? I should then be able to show it on the VF page with something like this?
You can put the code for the searchResults directly in the get:
or write a sepparate getsearchResults() method. See here about getters and setters: http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_methods.htm
Adrian
I think I've almost got this working, but I've just run into a problem.
The 'Parent' field on the account is a lookup field that seems to hold the parent account name. I need to get the 'AccountNumber' field from the parent account to use in the SOQL query as the discount objects only hold the account number.
Any ideas on how I can achieve this?
Parent.AccountNumber ? :)
Geez, I feel like I'm REALLY close with this but it just not happening!
My controller extension now looks like this:
And my VF page looks like this:
But when I load an account page I get this error where the VF page should be:
Content cannot be displayed: SObject row was retrieved via SOQL without querying the requested field: Account.ParentId
Obviously I'm still doing something wrong here, any ideas on what it might be?
Also, is it possible to make the VF page span both columns on the account page layout?
You are pretty close. :) Hang in there.
So, from what I read in the documentation not all the fields of the account are readily available. See here: http://www.salesforce.com/us/developer/docs/pages/Content/apex_pages_standardcontroller.htm
"Note that only the fields that are referenced in the associated Visualforce markup are available for querying on this SObject. All other fields, including fields from any related objects, must be queried using a SOQL expression."
So you'll need to query all the necessary fields in the constructor.
What do you mean "make the VF page span both columns on the account page layout"? Check the layout section options(the wrench in the right corner) to see if you cannot modify it from there(I might be wrong cause I don't really know your problem).
Have a nice day,
Adrian
You my friend are a legend! Thanks so much for your help!
Now I just need to figure out how to create aPDF of it LOL
:)... I try to be helpful when I think I know the answer.
For pdf you just need to add the renderas attribute to the page element:
The problem would be how do you want to generate this pdf? I would suggest creating a custom button that opens a different page that has the same code and the renderas specified.
Adrian
I did think about that but then I wondered how I would get the account number in the PDf page? The controller extension is pulling the discount details based on the account on the current page, but if the button navigates to a new page then won't I be missing the account details in the query?
Nevermind, I figures it out! Thanks again!