- Home
- Technical Library
- Boards
- Cookbook
- Code Share
- Blogs
- Partners
-
More
-
Services
- Training & Certification
- Support
-
Galleries
- Force.com Sites Gallery
- Chatter Challenge Entries
-
Other Web Sites
- Salesforce.com
- Database.com
- AppExchange
- CRM Community
-
Discussions
- Announcements
- General Development
- Schema Development
- New to Cloud Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules Discussion
- Security
- Mobile
- Force.com Sites
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby Development
- Adobe Flash Builder for Force.com
- Desktop Integration
- REST API Integration
- Streaming API
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- Excel Connector
- AJAX Toolkit & S-controls
- Force.com Builder & Native Apps
- AppExchange Directory & Packaging
- Force.com Labs Projects
- Open Source
- Site.com
- Jobs Board - Administrators
- Jobs Board - Developers
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- Simple custom extension test method
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Simple custom extension test method
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-24-2012 02:29 PM
I have what I believe is a very simple controller extension, and I cant seem to get any higher the 66% coverage on my test.
The page is a page for creating a new custom object (Intervention__c), this page is called from a button on a contact page. I pass the contact id as a param for this page.
I would apprecitae any help.
public class newInterventionCONT {
Public String ConID = System.currentPagereference().getParameters().get( '00Nd000000308OV');
public Contact myCon;
public newInterventionCONT(ApexPages.StandardController controller) {
myCon= [SELECT Name, Id FROM Contact WHERE Id =
:System.currentPagereference().getParameters().get ('00Nd000000308OV')];
}
public Contact getMyCon(){
return myCon;
}
static testMethod void testgetConMethod() {
PageReference pg = Page.intervention;
Test.setCurrentPage(pg);
Contact myContact = new Contact();
myContact.firstName = 'Joe';
myContact.lastName = 'Schmoe';
insert myContact;
ApexPages.StandardController stanCont = new ApexPages.standardController(myContact);
newInterventionCONT controller = new newInterventionCONT(stanCont);
string conFirstName = controller.getmyCon().FirstName;
string conLastName = controller.getmyCon().LastName;
string conID = controller.getmyCon().ID;
}
}
Thanks,
Chris
Solved! Go to Solution.
Re: Simple custom extension test method
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-24-2012 04:12 PM
I believe you will have to put the parameter on the pagereference before calling the method:
after you set the current page (Create the contact before this):
Contact myContact = new Contact();
myContact.firstName = 'Joe';
myContact.lastName = 'Schmoe';
insert myContact;
PageReference pg = Page.intervention;
Test.setCurrentPage(pg);
System.currentPagereference().getParameters().put( '00Nd000000308OV',myContact.id);
ApexPages.StandardController stanCont = new ApexPages.standardController(myContact);
newInterventionCONT controller = new newInterventionCONT(stanCont);
string conFirstName = controller.getmyCon().FirstName;
string conLastName = controller.getmyCon().LastName;
string conID = controller.getmyCon().ID;
}
Re: Simple custom extension test method
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-24-2012 06:54 PM
It looks like your controller is really an extension of the Contact standard controller. A Contact controller extension can be created like this, given that your Page named Intervention uses <apex:page standardController="Contact" extensions="newInterventionCont">
public class newInterventionCont {
private final Contact myCon;
public newInterventionCONT( ApexPages.StandardController controller ) {
myCont = ( Contact ) controller.getRecord();
}
public Contact getMyCon() {
return myCon;
}
static testMethod void testGetConMethod() {
Contact c = new Contact( FirstName = 'Joe', Lastame = 'Schmoe' );
insert c;
PageReference pg = Page.Intervention;
Test.setCurrentPage( pg );
ApexPages.StandardController stndController = new ApexPages.StandardController( c );
newInterventionCONT controller = new InterventionCONT( stndController );
Contact testCont = controller.getMyCon();
System.assertEquals( 'Joe', testCont.FirstName );
System.assertEquals( 'Schmoe', testCont.LastName );
}
}
Not sure if that helps since it really doesn't address the issue of creating you Intervention object.
The Flywheel Group
www.theflywheelgroup.com

