Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8395215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:14:38+00:00 2026-06-09T20:14:38+00:00

In Apex Unit tests why doesn’t the MyConrtoller myCont = new MyController(StandardContoller); call set

  • 0

In Apex Unit tests why doesn’t the MyConrtoller myCont = new MyController(StandardContoller); call set the current page?

For instance if I have this page:

<apex:page standardController="DB_Object__c" extensions="MyExtension">
  <apex:form id="detail_list">
    <apex:detail />
    <apex:actionStatus id="readStatus">
    <apex:facet name="start">
        Loading, please wait...
   </apex:facet>
    <apex:facet name="stop"><apex:outputPanel >
        <apex:commandButton action="{!readData}"
            value="Update Data"
            rerender="detail_list"
            status="readStatus"/>
        {!remainingRecords}</apex:outputPanel>
    </apex:facet>
   </apex:actionStatus>
   </apex:form>
</apex:page> 

If my unit tests creates this:

DB_Object__c dbObj = new DB_Object__c();
dbObj.Name = 'test';
dbObj.Setting = 'aSetting';
insert dbObj;
Test.setCurrentPageReference(Page.Demo);
ApexPages.StandardController sc = new ApexPages.StandardController(dbObj);
MyExtension myExt = new MyExtension(sc);

Why does ApexPages.currentPage().getParameters().get('id'); fail? I have to do:

ApexPages.currentPage().getParameters().put('id',dbObj.id);

What is the point of passing in the dbObj to StandardController if it doesn’t do anything with it? Is the intent that you send in a blank object and the extenstion uses this object? There doesn’t seem to be a lot of documentation for StandardControllers and Unit Testing…

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:14:40+00:00Added an answer on June 9, 2026 at 8:14 pm

    One way to go about this in a test scenario would be something like this:

    // at first you have to create the object
    DB_Object__c dbObj = new DB_Object__c();
    dbObj.Name = 'test';
    dbObj.Setting = 'aSetting';
    insert dbObj;
    
    // then you'd call the vf page with the id query paramter
    Test.setCurrentPageReference(Page.Demo);
    ApexPages.currentPage().getParameters().put('id', dbObj.Id);
    dbObj = [Select All, Fields, You, Need From DB_Object__c Where Id = :ApexPages.currentPage().getParamters().get('id')];
    
    // then the StandardController & controller extension get initiated
    ApexPages.StandardController sc = new ApexPages.StandardController(dbObj);
    MyExtension myExt = new MyExtension(sc);
    

    Now to your question why does getParameters().get('id') fail? You can initiate a StandardController without a record id which would give you a new record and automatically insert the record if you use the default save PageReference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Oracle APEX and I have a report region in a page that
I'm pretty new to APEX ( well, just started using it ~an hour ago),
i want to call a apex method from a custom Button I realise we
I have two apex:datatable in my VF page. I need an option of printing
Friends, My apex page has several different radio groups, each one can have the
Apparently a new feature of the Spring '12 / v24.0 release of Apex in
In Oracle ApEx, I have 6 regions on one page. Within Region 5, I
I've done writing code on salesforce and in order to release the unit tests
I have apex tag that generate input text field. <apex:page id=my_page> <apex:inputText id=foo id=c_txt></apex:inputText>
I'm trying to install new apex theme but the problem is that I don't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.