I am overriding the 'New' button on the WorkOrder standard object with a Visualforce page. My users will be creating their WorkOrder records from the Case object. I want to get the CaseId using the StandardController addFields() method in the page constructor.

This is the controller code:

public class TestCon {

    public WorkOrder workRecord {get; set;}

    public TestCon(ApexPages.StandardController stdCon) {
        stdCon.addFields(new List<String>{'CaseId'});
        this.workRecord = (WorkOrder)stdCon.getRecord();
        System.debug('workRecord: ' + workRecord);


An empty 'workRecord' is returned in the log and workRecord.CaseId returns null.

When I use the same code for a different object, e.g. overriding the Case New button and returning ContactId the code works as expected and ContactId is available to me in the controller extension.


This code for a Case controller extension does return the ContactId, I can't see any material difference myself.

public class TestCon {

    public Case caseRecord {get; set;}

    public TestCon(ApexPages.StandardController stdCon) {
        stdCon.addFields(new List<String>{'ContactId'});
        this.caseRecord = (Case)stdCon.getRecord();
        System.debug('caseRecord: ' + caseRecord);

  • What API version is your VF page & controller class using? – TSmith Oct 31 '17 at 9:06
  • 2
    Because you are overriding New button so Work Order don't have any value thats why you get an empty WO. – Tushar Sharma Oct 31 '17 at 9:26
  • My understanding is you do get the Is from the parent record where the New button was pressed by the user. When writing the exact same code for Case object I receive the ContactId when the pressing New on a Contact record. Please advise why this would be different. Thanks – KReader Oct 31 '17 at 10:22

Your Answer

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

Browse other questions tagged or ask your own question.