function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ramesh SomalagariRamesh Somalagari 

How to call the controller to VF page with parameter

How to call the controller to VF page with parameter?I have two Visual force pages, and two controllers

<apex:page standardController="Account" extensions="NewAndExistingController" id="demoId" >
    <apex:pageBlock >
     <br> </br>
<apex:outputField value="{!a.Id}"/> <br> </br>
       <apex:form >
          <apex:pageBlock >
               <apex:commandButton value="Call visualforce Page" action="{!click}"/>

VF page:XYZ

<apex:page standardController="Order__c" extensions="MyOrderPadController" >
    <apex:detail />
        <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!edit}" value="Edit"/>
                <apex:commandButton action="{!reset}" value="Cancel" />
            <apex:pageBlockSection columns="2" title="Order Pad">
            <apex:inputField value="{!Order__c.Order_Description__c}"  />
                    <apex:inputField value="{!Order__c.Creat_Date__c}"  />
                    <apex:inputField value="{!Order__c.Closed_Date__c}"  />
                     <apex:inputField value="{!Order__c.Conformation__c}"  /> 


public class NewAndExistingController {Public Account a{get;set;}public String accId;    public NewAndExistingController(ApexPages.StandardController controller) {    try{    a =[select id,name,accountnumber,annualrevenue from account where id=:controller.getId()];    MyOrderPadController.staticVar =a.Id;    }catch(exception e){}    }         public PageReference click() {        PageReference openvfpage = New Pagereference('/apex'+'/XYZ);     openvfpage.setRedirect(false);  return openvfpage ;        }    public NewAndExistingController() {    }   }

Controller: MyOrderPadController
public class MyOrderPadController {    public Order__c order{ get; private set; }        public static  String staticVar;       public String instanceVar {get; set;}           NewAndExistingController  test = new NewAndExistingController ();           public MyOrderPadController ()       {            instanceVar = staticVar;       }    public MyOrderPadController(ApexPages.StandardController sc) {        order = (Order__c)sc.getRecord();       }public PageReference edit()      {            return null;             }     public PageReference reset()     {          PageReference newpage = new PageReference(System.currentPageReference().getURL());          newpage.setRedirect(true);          return newpage;    }     public PageReference save()      {          TRY          {                             order.Name = 'Demo Test Order '+order.Order_Description__c;               order.Order_Description__c =order.Order_Description__c+':====>'+staticVar ;                order.Account__c = '0019000000NAr7bAAD';//for testing only                            IF(order.Conformation__c == TRUE){                                              INSERT order;                     PageReference newpage = new PageReference(System.currentPageReference().getURL());                    newpage.setRedirect(true);                    return newpage;                         }                                                            }                       catch(System.DMLException e)           {            ApexPages.addMessages(e);            SYSTEM.DEBUG('ERROR ORDER PAD CONTROLLER :'+e);            return null;          }        //  After Save, navigate to the default view page:        //return (new ApexPages.StandardController(order)).view();        return null;             }   }

The  "DEMO" VF page added to Account under the one section ,As of  now I am getting  Account Id in the controller "NewAndExistingController" .This controller again called to the VF page "XYZ" .How to access this Account id in controller "MyOrderPadController".

I want get account id in the "MyOrderPadController" Any idea please share with me.


In the pagereference calling the second page add a URL parameter &accid=YOURACCOUNTID

then in the second page in the constructor, get the paramater and assign it to a variable.


In the second page, if the record is already populated add
<apex:outputField value="{!order.Account__c}" rendered="false"/>

then when you call getrecord() in your constructor the order.Account__c should be populated
piyush parmarpiyush parmar

Once you call one visualforce page to another. It's new transaction, So you will not get the account Id even if  set to the nextController static variable.

So you have to pass the account value from one page to another page as a visualforce page parameter.