I have a custom controller and VF page which allow my users to create and save a contract by using several information fields on the opportunity and related account page. Since this was first created, new fields were added to the opportunity page. I would like to add a few of them to the VF page but I can't because they are not included in the original controller. How can I achieve this? Do I need to change the whole controller? (The horror) ...or can I just write an extension with the fields that I need to add and put it in the VF page? Thank you so much for any help

  • do you have any standard controller of this ?
    – Himanshu
    Nov 9, 2015 at 12:16
  • The standard controller for this would be the opportunity controller but it is not included in the VF page. I have thought of using the Opportunity standard controller as an extension on the VF but was afraid that might clash with the logic used in the custom controller. Should/can I use the standard controller as an extension to the custom one?
    – Askre
    Nov 9, 2015 at 12:22
  • update this question with your vf page and apex class. let us see your current implementation.
    – Himanshu
    Nov 9, 2015 at 12:23

2 Answers 2


If you are not currently using a standard controller you may have to update your Controller to be able to do so.

If you do not see a line in your controller like:

public YOURCONTROLLERNAME (ApexPages.standardController ...){...}

Then you will have to add that to use a standard controller. You cannot use a standard controller to a page as an extension, rather it is the other way around. You would do this:

<apex:page standardController="Opportunity" extensions="YOUR PREVIOUS CONTROLLER NAMES"/>

You will have to move the code from the original instantiation method to the new one with the standardController or simply use this() as the code body in the standardController instantiation.

Adding a standard controller should not mess with your current functionality as extension methods are always checked first before standardController methods. (i.e. a save method will override the standardController save method).

Then you can add fields to the VF page that are not in the SOQL as long as your page is launched with an id parameter


Ok I see that it is going to be slightly more difficult than anticipated. Can i just write a controller to exclusively add the fields that I need and use it as an extension for my VF page? Something like this:

public class extensiontocontract {
    public String jobId {get;set;}
    public Opportunity opp {get;set;}
    public extensiontocontract(){
      jobId = ApexPages.currentPage().getParameters().get('jobId');
      opp = [SELECT Account.ShippingStreet,Account.ShippingCity,Account.ShippingState,Account.ShippingPostalCode,
           FROM Opportunity WHERE Id =: jobId];

  • this is not an answer and should be added back into the original post
    – cropredy
    Nov 10, 2015 at 20:57

You must log in to answer this question.

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