You need to sign in to do that
Don't have an account?
Benedetto Virzi 17
Contact field Accountid in test
Hi,
I have a liltte problem with accountid in my test class. In my test method I create account and contact in this way:
With the system.debug I have seen that the Accountid filed in Contact record, is different from idAccount variable populeted by selecting Account record by name. How is it possible?
Benny
I have a liltte problem with accountid in my test class. In my test method I create account and contact in this way:
Account a = new Account(name='Mycompany'); insert a; Contact c = new Contact(Accountid=a.id, firstname='Mario', lastname='Rossi',Codice_Cliente__c='001'); insert c;In my production class I do this:
private static Account idAccount; idAccount = [select id from Account where name='MyCompany']; id idContact=[select id from Contact where Accountid=:idAccount.Id].id;But second select, fail.
With the system.debug I have seen that the Accountid filed in Contact record, is different from idAccount variable populeted by selecting Account record by name. How is it possible?
Benny
I see that name for accounts are different: one is called 'Mycompany' and the other one - 'MyCompany', therefore you are querying a different account in your production class.
Cheers!
thanks for the replay but this is only an example. In my code the string it's ok.
Can you also provide code with System.debug code and result, which you are getting.
Test classes records are imaginary records, those never created in the org database. So please won't confuse with those ids.
If you will check those id in your org then you will found error like : Data not avaliable.
In the test class always palace @isTest(seeAllData = false) on top of class & never check with hard coded ids.
I think you are receiving error like : No row found.
If this answers your question then hit Like and mark it as solution!
i don't use hard coded ids. For this I work with the account name. I create account with fixed name in test class and with the same name i do select in the production class. I'm confused!!
Benny