You need to sign in to do that
Don't have an account?
Mel Lisau
How can I populate required fields to creata test for SObjects ?
If i need to creat an Order , I need to first creat an Account and then assign the AccountId to the Order, like the following
Account a = new Account();
a.Name = 'Test';
insert a;
Order order = new Order(
AccountId = a.Id,
Status='Draft',
EffectiveDate = Date.today());
insert order;
Is there a way to create an Order and the required fields will be populated including the AccountId that is linked to the Account?
Reason is that I am looking at dynamically crating tests for my SObjects.
So if i have a trigger on Order (after insert) , I want to create a test for this but do it through a dynamic templating that I can use for al SObjects .
Thanks
Account a = new Account();
a.Name = 'Test';
insert a;
Order order = new Order(
AccountId = a.Id,
Status='Draft',
EffectiveDate = Date.today());
insert order;
Is there a way to create an Order and the required fields will be populated including the AccountId that is linked to the Account?
Reason is that I am looking at dynamically crating tests for my SObjects.
So if i have a trigger on Order (after insert) , I want to create a test for this but do it through a dynamic templating that I can use for al SObjects .
Thanks
All Answers
I basically read a list of objects and determine what i need to create so if i have something like:
[0]
[0] "Product"
[1] "Status"
[2] "String"
[3] null
[1]
[0] "Product"
[1] "Effective Date"
[2] "String"
[3] null
[2]
[0] "Product"
[1] "AccountId"
[2] "Guid"
[3] "Account"
[3]
[0] "Product"
[1] "Name"
[2] "String"
[3] null
[4]
[0] "Account"
[1] "FirstName"
[2] "String"
[3] null
[5]
[0] "Account"
[1] "LastName" <
[2] "String"
[3] null
I will need to ceate the following:
For Account:
@isTest
public class TestRTT_Account_I
{
public static testMethod void Test_Account_I()
{
List<Account> genericList = new List<Account>();
Account a = new Account(FirstName = 'TestFirstName', LastName = 'TestLastName');
Account acc = new Account(FirstName = 'TestFirstName01', LastName = 'TestLastName01');
genericList.add(a);
genericList.add(acc);
insert genericList;
}
}
and the samer for product.
Sol its dynamically creating the test ?