Hi I sent my entire code


<apex:page controller="NewAndExistingController" >

       <apex:form >
          <apex:pageBlock >
               <apex:commandButton value="Call visualforce Page" action="{!click}"/>



public class NewAndExistingController {
    Account acc = NEW Account();   
    public PageReference click() { 
        PageReference openvfpage = New Pagereference('/apex'+'/XYZ');
        return openvfpage ;        
   public NewAndExistingController() {    }  


<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: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 MyOrderPadController { 
    public Order__c order{ 
        get; private set;

    public MyOrderPadController(ApexPages.StandardController sc){     
        order = (Order__c)sc.getRecord(); 

    public PageReference save(){       
        order.Account__c = '0019000000NAr7bAAD';//for testing only                
        IF(order.Conformation__c == TRUE){
            INSERT order;               
            PageReference newpage = new PageReference(System.currentPageReference().getURL());                    
            return newpage;                        
        return null;          

Here DEMO VF page attched the Account Object under the one section.it show like see the screen shortenter image description here

When ever user click the "Call visualforce Page" button then go to XYZ VF page,In this page how to get the current Account Id and how to pass Account Id to "MyOrderPadController".As of now Account id is hard coded how to get account id?

the above code is working as accepted or I have implemt wroung way Please let me know as soon as possible

2 Answers 2


You are accessing your Order__c object incorrectly. You should be pulling the order off of the StandardController using the getRecord() method.

Your controller's constructor should look something like:

public class myController{
    public Order__c order{get; set;}  
    public myController(ApexPages.StandardController sc){
        order = (Order__c)sc.getRecord();
    // Other logic here

You should read up on the proper technique of Building a Controller Extension. There are some other things you may want to consider as well. For instance, I see you have a hard coded Account Id in your code. This is considered bad practice. You should also look into setting up proper transaction control utilizing the Database class to setSavepoint() and rollback().


Right now you are referencing an object named "Order__c" in your VF, but the variable is named "order" in your custom controller. You need to match the field names on your VF page to your controller extension. If you want the data from your VF page to show up in your custom controller, update the variable names.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .