You need to sign in to do that
Don't have an account?
Trigger on Account to update Description field
I have written a practice trigger Which populates the Description feild on Account object If the Industry = Banking. From the UI it works good. Also get 100 Test coverage. I feel the trigger is not firing from Test class because my System.debug are not logging the fields I need. I would be very thankful if anyone can point out my mistake. I would like to add my System.assertEquals are failing. Please help me learn
/*Trigger*/
This is my test Class
/*Trigger*/
trigger UpdateDescriptionOnAccount on Account (before insert) { list<Account> ActList=new list<Account>(); for(Account a :Trigger.new) { if(a.Industry=='Banking' && a.Description == Null) { a.Description='This is a Banking Account'; ActList.add(a); } } //insert ActList; }
This is my test Class
/*Test Class*/ @isTest public class TestUpdateDescriptionOnAccount { static testmethod void TestUpdate() { Account a = New Account(Name='Test Account 1',Industry='Banking'); insert a; System.debug('Account Inserted '+a.Name + 'Description ='+a.Description +a.Industry); //system.assertEquals('This is a Banking Account',a.Description); Account b = New Account(Name='Test Account 2',Industry='Agriculture'); insert b; //System.assertEquals(Null, b.Description); list<Account>testAccount = new List<Account>(); for(integer i=0;i<200;i++) { Account c = new Account(Name='Account '+i, Industry='Banking'); testAccount.add(c); } test.startTest(); insert testAccount; test.stopTest(); for(Account d : TestAccount) { //system.assertEquals('This is a Banking Account',d.Description); System.debug('Account Inserted '+d.Name + 'Description ='+d.Description); } } }
after test.StopTest();
testAccount = [select id, name, description from account];
this will get you the new results after the update
All Answers
after test.StopTest();
testAccount = [select id, name, description from account];
this will get you the new results after the update
System.AssertEquals('This is a Banking Account',acc.Description);