+ Start a Discussion

Apex test issue, Please help?


When you are working with object X and before you can save a related object through lookup can not have a status of Y how do you write the test code across objects?


Thank you,


Ritesh AswaneyRitesh Aswaney

Not sure I completely understand, but here is a simple Account - Contact example


Account acc = new Account (Name = 'The Beatles');

insert acc; //after insert, acc will have the Id set on it, hence can be used in the Contact insert


Contact con = new Contact(FirstName = 'John', LastName = 'Lenon', AccountId = acc.Id);

insert con;