You need to sign in to do that
Don't have an account?
Tom Barad 11
Passing Parameters to a Custom Controller from VisualForce Page
Just starting out and I have a simple issue. I'm not able to pass a value from an inputField on a VF page to a custom controller. Based on my searching, it should be easy. Any help would be appreciated.
Here is my VF page:
Here is my VF page:
<apex:page standardController="Campaign" extensions="MarketoMergeFieldExtension"> <apex:form > <apex:pageBlock title="Marketo Merge Field Setter"> <apex:PageBlockSection > <apex:outputField value="{!campaign.Name}"/> </apex:PageBlockSection> <apex:PageBlockSection title="Choose Marketo Merge Fields"> <apex:inputField value="{!campaign.Marketo_Merge_Field_X__c}"/> </apex:PageBlockSection> <apex:PageBlockSection > <apex:commandButton action="{!processMarketoMergeField}" value="Go!"> <apex:param name="mergefieldtextparm" value="{!campaign.Marketo_Merge_Field_X__c}" assignTo="{!mergefieldtext}"/> </apex:commandButton> </apex:PageBlockSection> </apex:pageBlock> </apex:form> </apex:page>And here is my custom controller:
public class MarketoMergeFieldExtension { public String mergefieldtext {get;set;} private final Campaign c; public MarketoMergeFieldExtension(ApexPages.StandardController controller) { this.c = (Campaign)controller.getRecord(); } public PageReference processMarketoMergeField() { system.debug('mergefieldtext: '+mergefieldtext); return null; } }Eventhough my picklist field Marketo_Merge_Field_X__c has a value, when I look at my Log, I see:
2:47:01:062 USER_DEBUG [23]|DEBUG|mergefieldtext: nullThanks in advance.
From what I think the problem is with your Campaign, ideally don't merge Standardcontroller and Custom in such a manner. If you declare your Campaign as Public Campaign you can directly refer it on the page and pass values.
So your controller will become (Warning: Untested code ahead)
And the page
Temme if this solves your problem, if it does make this as an Answer so it helps others.
The corrected page code is: