You need to sign in to do that
Don't have an account?
Baguiar
Create account and a contact and reference account on new contact
Hi,
might be simple but I'm trying to reference this new contact with the test account created, this is a test for a controller.
on the NEW contact "con", I need it to be related to the account acc that I've just created. I'm trying account.name='xxxx" but doesn;' work.
@isTest private class TestKeyLeadership { static testMethod void testGetLeaders() { // insert a test account Account acc=new Account(Name='Test123'); insert acc; // insert a test Contact Contact con=new Contact(FirstName='Lester', Lastname='DbigTester', account=acc.id, email='123123123@888555.com'); insert con; // insert a test Leadership Code List<leadership_position_code__c> LDS=new List<leadership_position_code__c>{new leadership_position_code__c(Contact__C='Lester DbigTester', position_type__C='Clergy', Position__C='Cantor', Start_Date__C='01/01/2011', Thru_date__C='01/02/2011' ), new leadership_position_code__c(Contact__C='Lester DbigTester', position_type__C='Officer', Position__C='President', Start_Date__C='01/01/2011' ), new leadership_position_code__c(Contact__C='Lester DbigTester', position_type__C='Clergy', Position__C='Senior (or only) Rabbi', Start_Date__C='01/01/2011' )}; insert LDS; // add the id to the current page ApexPages.currentPage.getParameters().put('id', acc.id); // instantiate the class under test KeyLeadership kl=new KeyLeadership(); List<Leadership_Position_code__c> leaders=kl.getLeaders(); System.assertEquals(2, leaders.size()); }
Thanks!
B
Actually found a little help on another post, by luck. modified to this:
But now I'm getting and error on the ApexPages.currentPage.getParameters().put('id', acc.id); ...
B
Hi Baguiar,
you need to set the Contact's AccountId field rather than Account e.g.,
You don't need the Saveresult either - your first piece of code should work just fine.
I recommend cross-referencing your testcode to the VF page so the page can't be deleted.
e.g.,
Hope this helps.
regards,
Manu
HI Manu and thanks for the reply!
the Contact inser is fine but I'm getting an error now on the ApexPages.currentPage.getParameters().put('id', acc.id);
. The error comes up as "Method does not exist or incorrect signature."
Really thanks for the test mehod on the page. I'm learning the test methods now and that was really good. Might need some more help on that.:)
HUmm.. tried that but now a Constructor not defined.... here is the Error:
Compile Error: Constructor not defined: [KeyLeadership].<Constructor>(ApexPages.StandardController)
Really thanks for your help!
Here is the code:
ANd the error not passing the test is: Failure Message: "System.StringException: Invalid id: Lester DbigTester", Failure Stack Trace: "Class.TestKeyLeadership.testGetLeaders: line 14, column 126 External entry point"
B
Found the isuue with the ID..
This: Contact__C='Lester DbigTester'
should be this: Contact__C=con.id
It is giving me 70% coverage though... need 5% more..
Code is good. it was a nother class on production causing the % on converage.