You need to sign in to do that
Don't have an account?
dfalso
Best way to automatically run controller methods at page instantiation?
Hi all, I'm pretty new to SalesForce development, so maybe this has been answered somewhere else and I missed it. If so, I apologize.
Anyway, I'm working with a custom object that has a one-to-many relationship with another custom object (in fact, I'll have a chain of about 5 when I'm done). I created a custom page and was confused when the detail object didn't inherit the master's Id. I found this link that (I think) is the same problem with a solution:
http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=5894
What I'm wondering now is the best way to run this class. FYI, I was initially planning on using a standard controller with this as an extension. Ideally, the class would run at page instantiation. I suppose I'd be okay with running it just before the save action. I'd ideally not do it as a trigger (this to me is an issue related to the custom page, not something that should happen globally - but maybe I'm wrong). Any recommendations? If I were to couple it to the save button, how would that go? Can an extension call a standard action (in which case I'd point the button at an extension method which would write the Id and then save)? If not, I think I need to write a custom controller, right?
Thanks for any assistance.
-Dominic
Anyway, I'm working with a custom object that has a one-to-many relationship with another custom object (in fact, I'll have a chain of about 5 when I'm done). I created a custom page and was confused when the detail object didn't inherit the master's Id. I found this link that (I think) is the same problem with a solution:
http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=5894
What I'm wondering now is the best way to run this class. FYI, I was initially planning on using a standard controller with this as an extension. Ideally, the class would run at page instantiation. I suppose I'd be okay with running it just before the save action. I'd ideally not do it as a trigger (this to me is an issue related to the custom page, not something that should happen globally - but maybe I'm wrong). Any recommendations? If I were to couple it to the save button, how would that go? Can an extension call a standard action (in which case I'd point the button at an extension method which would write the Id and then save)? If not, I think I need to write a custom controller, right?
Thanks for any assistance.
-Dominic
So whatever you want to run when your page is called, put it in your controller's constructor (or the constructor of your extension if that's what you're using).
If you instantiate a class yourself you do something like :
MyCustomClass mc = new MyCustomClass();
but a controller extension will be instantiated by the VF framework for you - and it will always receive a reference to the standardcontroller.
hope this helps,
David
Thanks for your help.
Message Edited by dfalso on 10-15-2008 01:59 PM