You need to sign in to do that
Don't have an account?
victor carcamo
trigger AccountTrigger on Account (after insert) {
if (Trigger.isBefore && Trigger.isInsert) {
AccountTriggerHandler.CreateAccounts(Trigger.New);
}
}
@isTest
public class AccountTriggerTest {
@isTest static void TestCreate200Records()
{
List<Account> accts = new List<Account>();
for(Integer i=0; i < 200; i++) {
Account acct = new Account(Name='Test Account ' + i, BillingState = 'CA');
accts.add(acct);
}
Test.startTest();
insert accts;
Test.stopTest();
System.assertEquals(200, [SELECT Count() FROM Account WHERE ShippingState = 'CA' ]);
}
}
public class AccountTriggerHandler {
public static void CreateAccounts(List<Account> acclist)
{
for(Account acc:acclist)
{
if(acc.ShippingState!=acc.BillingState)
{
acc.ShippingState = acc.BillingState;
}
}
}
}
I've tried test--> run all and still have the same error, i dont know what else to do
The 'AccountTrigger' Trigger does not appear to be working correctly. Inserted records did not have matching BillingState and ShippingState values.
trigger AccountTrigger on Account (after insert) {
if (Trigger.isBefore && Trigger.isInsert) {
AccountTriggerHandler.CreateAccounts(Trigger.New);
}
}
@isTest
public class AccountTriggerTest {
@isTest static void TestCreate200Records()
{
List<Account> accts = new List<Account>();
for(Integer i=0; i < 200; i++) {
Account acct = new Account(Name='Test Account ' + i, BillingState = 'CA');
accts.add(acct);
}
Test.startTest();
insert accts;
Test.stopTest();
System.assertEquals(200, [SELECT Count() FROM Account WHERE ShippingState = 'CA' ]);
}
}
public class AccountTriggerHandler {
public static void CreateAccounts(List<Account> acclist)
{
for(Account acc:acclist)
{
if(acc.ShippingState!=acc.BillingState)
{
acc.ShippingState = acc.BillingState;
}
}
}
}
I've tried test--> run all and still have the same error, i dont know what else to do
Change the trigger event to Before Insert.
trigger AccountTrigger on Account (before insert)
Apex Trigger: ( Before Insert )
Apex Class:
Test Class:
Thanks,
Maharajan.C