You need to sign in to do that
Don't have an account?

Relation ship query issue
Hello Everyone,
could you provide me soluction for displaying relationship data, in the below code debug statement always displaying NULL( in line number 17)
Thanks
Vijay
could you provide me soluction for displaying relationship data, in the below code debug statement always displaying NULL( in line number 17)
@istest public class testdatafactory { public static List<account > accountRecords(Integer num) { List < account > AccList = new List < account > (); for (Integer i = 0; i < num; i++) { account Acc = new account (); Acc.name = 'Account Testdata '+ i; Acc.BillingCity = 'chennai'; Acc.BillingCountry = 'India'; Acc.BillingPostalCode = '6000003'; Acc.BillingState = 'tamilnadu'; Acc.BillingStreet = 'West street'; AccList.add(Acc); } insert AccList; return AccList; } public static List<contact > contactRecords(Integer num,list<account> acc) { List < contact > AccList = new List < contact > (); for (Integer i = 0; i < num; i++) { contact c = new contact (); c.LastName= ' Last Name'+i; c.accountID=acc[i].id; AccList.add(c); } insert AccList; return AccList; } } @istest public class TestClass { static testmethod void Unittest() { list<account> acc= testdatafactory.accountRecords(10); //list<account> acclist=[select name,BillingCity from account]; list<contact> con= testdatafactory.contactRecords(10,acc); for(contact c:con) { system.debug('===>'+c.account.name); } }
Thanks
Vijay
If you run the statement you will see that accountId will get displayed. So there are no such errors are occuring and methods of testdatafactory class are performing well.
To display relationship data you need to perform separate SOQL query based on contacts. Hope it helps.
P.S. - Please mark this answer as closed if you are happy.
All Answers
If you run the statement you will see that accountId will get displayed. So there are no such errors are occuring and methods of testdatafactory class are performing well.
To display relationship data you need to perform separate SOQL query based on contacts. Hope it helps.
P.S. - Please mark this answer as closed if you are happy.