You need to sign in to do that
Don't have an account?
Jvallee
Access Page Component w/ Apex
I'm still new to this, so hopefully I am using the right terms:
I have created a Controller Extention as an Apex class that will in effect override the !save of the standard controller. What I was hoping to do is save a field to a related object in this method, which I have been able to do, but I need to get the value that I will write from an <apex:inputField> page component. Is this possible? I can't seem to find a way to reference these components in Apex.
Code:
public class LeadTouchExtension{ public final Lead_Touch__c leadTouch; //Create a new save action ApexPages.Action saveAction = new ApexPages.Action('{!LeadTouchSave( string )}'); public LeadTouchExtension ( ApexPages.StandardController stdController ) { this.leadTouch = (Lead_Touch__c)stdController.getRecord(); } public void LeadTouchSave() { try{ for( Lead relatedLead : [Select ID, Salutation, FirstName, LastName FROM lead WHERE Lead.ID = :leadTouch.Lead__c LIMIT 1 ] ) { //this needs to reference the Form and any pageBlock (maybe page block section) by name. relatedLead.FirstName = ***Need to reference page component here!*** update relatedLead; } } catch( DmlException ex ) { ApexPages.addMessages(ex); } } }
Jeremy
Jeremy, thanks so much for the reply. I checked out the link that you posted, I've read it a few times and I'm sorry to say that I don't see the solution, but maybe I'm still too new at this.
The example you link has this page definition
In this example, a standard controller for an Account object is used for the page. So the inputField is set to {!account.name}
In my example, the standard controller is set to a custom object LeadTouch, which has a related Lead object. I fill my inputField with {! Lead_Touch__c.Lead__r.FirstName} and all is good for the load. The trouble is, when I call {!save}, that will not save to the related Lead and usually causes an error. So I have created an Extension to the Standard Contoller (see my first post.) In the extension I define LeadTouchSave() I have been able to to update the Lead record, but I don't know how to get the value of the inputField for the update. I need to get the users input for this to work. And from what I understand about the example you referenced is that it works with the record associated with the standard controller.
Any suggestions?
Thanks Again,
Jason
Then in your vf page, you can do something like this:
In your save method you have to manually update the lead by doing this:
I'm not sure if your use case is create or update. If create, change the above to the create call instead of update.
Jeremy
Message Edited by jeremy_ross on 10-07-2008 02:21 PM