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
petergascoynepetergascoyne 

Test Data Objects

Hi people,

 

The problem I have is, I have an application I have been working on and to test it I need a large amount of Custom Objects,  over 100.

 

What would be the best way to create 100 test Custom Objects?

 

Would I be able to quickly add and remove these at anytime?

 

Thanks

 

Peter

Cory CowgillCory Cowgill

Please review the Force.com Apex Code Developers Guide (http://www.salesforce.com/us/developer/docs/apexcode/index.htm) , speciifcally the section 'Testing Apex'

 

1. Any records you create in a method marked 'testMethod' will be not be commited to the DB after the test is run. You can just think of it as automatically deleting all your test records.

 

2. Inside your testMEthod, to create a large amount ot test objects you can do soething like this:

 

List<Custom__c> customList = new List<Custom__c>():

for(Integer x = 0; x < 100; x++)

{

      Custom__c customObj = new Custom__c();

      customObj.Name = 'UnitTestName' + x;

      customList.add(customObj);

}

insert customList;

Bhawani SharmaBhawani Sharma

you are talking about the records or objects ?

petergascoynepetergascoyne

I am talking about the actual Custom Object not a record of the object.

 

I think there is a solution maybe using the metadata API.

 

Thanks

Bhawani SharmaBhawani Sharma

Yes then you can create the objec via metadeta api.