0

Sorry for the newbie question ... I'm just starting out and I have a simple issue that I'm hoping someone will be able to help me with. 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.

My Visualforce 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 extension:

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;
    }   
}

Even though my picklist field Marketo_Merge_Field_X__c has a value, when I look at my Log, I see:

1   2:47:01:062 USER_DEBUG [23]|DEBUG|mergefieldtext: null

Thanks in advance.

  • 2
    You need to add a rerender attribute to you command button. It can be anything like rerender="fake" or an actual component id – Eric Mar 22 '15 at 19:49
1

Thanks for answering ... Got this to work (thanks, Sforce.Ninja on developer.salesforce.com!). Just posting the answer in case someone else comes across this.

The problem was that I set "Campaign c" to private and overthought the passing of parameters ...

Here is the fixed 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:PageBlockSection>            
        </apex:pageBlock>
    </apex:form>
</apex:page>

Here is the fixed extension:

public class MarketoMergeFieldExtension {

    public String mergefieldtext {get;set;}
    public Campaign c {get;set;}

    public MarketoMergeFieldExtension(ApexPages.StandardController controller) {
        this.c = (Campaign)controller.getRecord();
    }

    public PageReference processMarketoMergeField() {
        system.debug('mergefieldtext: '+mergefieldtext);
       return null;
    }   
}
| improve this answer | |
0

You cannot reference twice the same field on the page, it will always get you the initial value of field, in this case 'null' If you need to assign the value of your field to your variable, do it directly into the controller.

<apex:commandButton action="{!processMarketoMergeField}" value="Go!" rerender="nothing" />

public PageReference processMarketoMergeField() {
    mergefieldtext = campaign.Marketo_Merge_Field_X__c;
    system.debug('mergefieldtext: '+mergefieldtext);
    return null;
}  
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.