function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
chennachenna 

Help with test class

I need to insert two fields project__c(masterdetail of another object),test_id__c into test object  in test class.

 

Can anyone help? i am new to force.com

Best Answer chosen by Admin (Salesforce Developers) 
ClintLeeClintLee

Do you mean that you need to add values into those fields in your test?

 

This might help.  You need to create the Master object first, then use its Id for the Detail object.

 

 

MasterObject master = new MasterObject( Name = 'Master Object' );

insert master;

 

DetailObject detail = new DetailObject( Name = 'Test Object'

                                                                      ,Project__c = master.Id

                                                                      ,Test_Id__c = '12345' );

insert detail;

 

Hope that helps!

 

~  Clint