You need to sign in to do that
Don't have an account?

Challenge Not yet complete... here's what's wrong: The 'AccountTrigger' Trigger does not appear to be working correctly. Inserted records did not have matching BillingState and ShippingState values.
Hi All,
I have a problem with this Challenge : https://developer.salesforce.com/trailhead/microsoft_dotnet/apex_basics_dotnet/execution_context
//AccountTriggerHandler
public class AccountTriggerHandler {
public static void CreateAccounts(List<Account> acclist){
for(Account a:acclist){
if(a.ShippingState!=a.BillingState){
a.BillingState=a.ShippingState;
}
}
}
}
//AccountTrigger
trigger AccountTrigger on Account (before insert)
{
if (Trigger.isBefore && Trigger.isInsert) {
AccountTriggerHandler.CreateAccounts(Trigger.new);
}
}
//AccountTriggerTest
@isTest
public class AccountTriggerTest {
@isTest static void TestCreate200Records(){
// Test Setup data
// Create 200 new Accounts
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 acct;
Test.stopTest();
for (Account a:accts){
System.assertEquals('CA', a.ShippingState, 'ERROR');
}
}
}
}
Can you help me please??
Thanks!
I have a problem with this Challenge : https://developer.salesforce.com/trailhead/microsoft_dotnet/apex_basics_dotnet/execution_context
//AccountTriggerHandler
public class AccountTriggerHandler {
public static void CreateAccounts(List<Account> acclist){
for(Account a:acclist){
if(a.ShippingState!=a.BillingState){
a.BillingState=a.ShippingState;
}
}
}
}
//AccountTrigger
trigger AccountTrigger on Account (before insert)
{
if (Trigger.isBefore && Trigger.isInsert) {
AccountTriggerHandler.CreateAccounts(Trigger.new);
}
}
//AccountTriggerTest
@isTest
public class AccountTriggerTest {
@isTest static void TestCreate200Records(){
// Test Setup data
// Create 200 new Accounts
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 acct;
Test.stopTest();
for (Account a:accts){
System.assertEquals('CA', a.ShippingState, 'ERROR');
}
}
}
}
Can you help me please??
Thanks!
Instead of:
Try:
Thank you but I already tried it and it doesn't work.
Please updated your Apex class and Test class like below
1) AccountTriggerHandler 2) AccountTriggerTest
Let us know if this will help you
Thanks
Amit Chaudhary
Write an Apex trigger that fires before records are inserted and ensures that the ShippingState field has the same value as the BillingState field.
Create an Apex class named AccountTriggerHandler that contains a public static method called CreateAccounts to accept the List of Account objects
For each Account record, before saving, ensure that the ShippingState field has the same value as the BillingState field
Write an Apex trigger named AccountTrigger that fires before records are inserted
The Apex trigger must call the AccountTriggerHandler.CreateAccounts() method with the collection of new records
Make sure you use the isBefore and isInsert trigger context variables
Create a test class named AccountTriggerTest that inserts 200 Account records with a BillingState of CA. After the insert, test to ensure that all 200 records have a ShippingState of CA
Before verifying this challenge, run your test class at least once using the Developer Console Run All feature.
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);
}
}
-------
public with sharing class AccountTriggerHandler {
public static void CreateAccounts (List<Account> accts) {
List<Account> acc = new List<Account>();
for (Account a : accts) {
if (a.ShippingState != a.BillingState)
{
a.ShippingState = a.BillingState;
acc.add(a);
}
acc.add(a);
}// end foreach
if (acc.size() > 0) {
insert acc;
}
}
}
-----
@isTest
public class AccountTriggerTest {
@isTest public static void TestCreateNewAccountInBulk(){
// Test Setup data
// Create 200 new Accounts
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);
}
// Perform Test
Test.startTest();
insert accts;
Test.stopTest();
// Verify that 200 new Accounts were inserted
List<Account> lstAccount = [SELECT ShippingState FROM Account ];
for (Account ac: lstAccount )
{
System.assertEquals('CA', ac.ShippingState, 'ERROR');
}
}
}
Please help