You need to sign in to do that
Don't have an account?
CB312
Controller Extension & Test Methods
Hi,
I just read through most of the boards including this recent post: http://forums.sforce.com/t5/Apex-Code-Development/Test-Methods-for-Extensions/td-p/260353
and I still am confused with the process for setting up my test method. (I've already registered for the March 30th class but any help between now and then would be much appreciated)
Here is my class:
public class POSystem { Public Purchase_Order__c po {get; set;} public POSystem(ApexPages.StandardController controller) {po = (Purchase_Order__c)controller.getRecord();} public List<Lead> getRelevantLeads() { List<Lead>Listofleads = [select id, company, Category__c, Subcategory__c, Name, Website, Email, Status, Phone, LeadSource, Last_Activity_Date__c from Lead WHERE ownerid = :po.assigned_to__c AND Category__c = :po.Category__c AND isconverted = false AND Subcategory__c = :po.Subcategory__c ORDER BY Last_Activity_Date__c ASC]; return Listofleads; }
and here is my *attenpt* at the test class
private testMethod static void testRelevantLeads(){ //String expected = '{cols: [{id: "col1", label: "Billing Country", type: "string"},{id: "col2", label: "Number of Opportunities", type: "number"}], rows: [{c:[{v: "MyCountry"},{v: 2.0}]}]}'; ApexPages.StandardController stc = new ApexPages.Standardcontroller(); POsystem con = new RelevantLeads (stc); //ApexPages.StandardController <POsystem> pos = new POSystem((new ApexPages.StandardController(testleads))); Lead l1 = new Lead(Company='l1', Division__c = 'Hampton Roads', Category__c = 'Health & Beauty', Subcategory__c = 'Dental'); Lead l2 = new Lead(Company='l2', Division__c = 'Hampton Roads', Category__c = 'Health & Beauty', Subcategory__c = 'Dental'); list <lead> testleads = new list<lead>(); testleads.add(l1); testleads.add(l2); //insert new List<Lead> {l1, l2}; String actual = pos.getListofleads(testleads); //System.assertEquals(expected, actual); }
Thanks!
Here's the gist of it
//The Record
Quote quote = [select id,opportunity.recordtypeid from quote where id = :q1.id];
I don't see you initialising your standard controller with the record.
Hey Ritesh,
Thanks for the repy, I acutually refrenced your post in the first line, I am using an extension on a custom object, not from a quote and am not using recordtype ids, I am acutally generating the fields at runtime based on the values in the current page. How do I setup the test class with those variables when they are determined at runtime and read via a hidden field on the vf page?
Hey
Not sure if the use of a custom object should change the basics - hopefully this helps