• victor carcamo
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
User-added image

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

 
User-added image

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

 
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!