+ Start a Discussion
Abhijeet Purohit01Abhijeet Purohit01 

Problem in test class...

Am writing a test class... The need is to include a field of a object which is lookup to itself..... How can I include?

 

 

If the field was lookup to some other object then I would have written something like this:

 

field =instance.id;

 

How to include a field which is lookup to itself?

 

Pls help.....

 

Abhijeet

Best Answer chosen by Admin (Salesforce Developers) 
sai.sfsai.sf

Account testAccount = new Account(name='Test Company Name');
insert testAccount;

Account testAccount2 = new Account(name='Test Company Name2',account__c = testAccount.Id);
insert testAccount2;

All Answers

sai.sfsai.sf

Account testAccount = new Account(name='Test Company Name');
insert testAccount;

Account testAccount2 = new Account(name='Test Company Name2',account__c = testAccount.Id);
insert testAccount2;

This was selected as the best answer
Abhijeet Purohit01Abhijeet Purohit01

BINGO!!! Thank you............