I have created a Vf page from which i need to fetch the value of new subcription type. I'm not able to pass the picklist value to the controller for creating a new subscription. I would really appreciate your help here.

This is my Vf page:

<apex:page standardController="Subscription__c" extensions="subscriptionController">
    <apex:form >

    <apex:pageBlock title="This Subscription" id="this_subscription">

         <!-- Terms List -->
         <apex:pageBlockTable value="{!Subscription__c }" var="ts">

             <apex:column title="Update subscription to">
                <apex:facet name="header">Update subscription to</apex:facet>
                <apex:inputField value="{! ts.update_Subscription__c }"/>


    <apex:pageBlockButtons >
         <apex:commandButton action="{!cloneWithTerms}" value="Clone with Terms" immediate="true"/>

This is the controller:

private Subscription__c subscription {get;set;}
private Subscription__c oldSub;
private Subscription__c newSub;

private ApexPages.StandardController stdController;

public subscriptionController(ApexPages.StandardController stdController) {
    this.subscription = (Subscription__c)stdController.getRecord();
    this.stdController = stdController;

    oldSub = [SELECT Id, Name, Contact__c, Startdate__c, Enddate__c,   update_Subscription__c FROM Subscription__c WHERE Id = :stdController.getId()];

public PageReference cloneWithTerms() {

        // new subscription with updated 'type' preference
        newSub = new Subscription__c();
        newSub.Contact__c = oldSub.Contact__c;
        newSub.Startdate__c = Date.today();
        newSub.Enddate__c = oldSub.Enddate__c;
        // Determine new subscriptiontype
        if (this.subscription.update_Subscription__c == '6M1') {            newSub.X6M1__c = TRUE;
        } else if (this.subscription.update_Subscription__c == '6M2') {     newSub.X6M2__c = TRUE;
        } else if (this.subscription.update_Subscription__c == '6MO') {     newSub.X6MO__c = TRUE;
        } else if (this.subscription.update_Subscription__c == '12M1') {    newSub.X12M1__c = TRUE;
        } else if (this.subscription.update_Subscription__c == '12M2') {    newSub.X12M2__c = TRUE;
        } else if (this.subscription.update_Subscription__c == '12MO') {    newSub.X12MO__c = TRUE;
        insert newSub ;

    }catch(exception e){                

    PageReference page = new Pagereference('/'+newSub.Id);
    return page;

Any suggestions on this?

  • Can you use <apex:pageBlockTable value="{!subscription}" var="ts"> Dec 12 '16 at 1:19

The immediate=true processes the action without any validation and thus does not pass anything to the controller (setters do not fire). It just executes the action.

It is a common stumbling block for those new to visual force.

<apex:pageBlockButtons >
         <apex:commandButton action="{!cloneWithTerms}" value="Clone with Terms"/>

As an aside if you want to prevent a page refresh simply add:


and if you actually want to rerender and do a partial page refresh then add the appropriate id to it:



Currently I run a query in the constructor because I'm not able to access this methods query results in the pagereference:

private String sortOrder = 'Collectiondate__c';
public List<Term__c> getTerms() {

List<Term__c> results = Database.query(
    'SELECT Id, Term__c FROM Term__c WHERE Collectiondate__c >= TODAY ' +
    'ORDER BY ' + sortOrder
return results;

Any suggestions on this?

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.