+ Start a Discussion
Robert WynterRobert Wynter 

Please Help a newbiee create a test class for the following trigger

It's been a long while since I looked into written Apex triggers. I successfully created one a year ago but neglected to creat a test class for it which has now come to bite me in th ARS. If someone can have pitty on me and help me create a test class that would be greatly appreciated
trigger updateAccountStatus on Opportunity (after insert, after update) 
list<Id> accIds = new list<Id>(); 

/* list<Account> accounts = new list<account>(); */ 
Map<Id, Account> accounts = new Map<Id, account>(); 
for(opportunity o:trigger.new){ 



for(account a:[select Id, Status__c from account where Id IN :accIds]){ 

for(opportunity opp:trigger.new){ 

a.Status__c = opp.Status__c; 
a.Approval_Progress__c = opp.StageName; 

accounts.put(a.Id, a); 
/* if(opp.Status__c=='Active'){ 




update accounts.values(); 
/* update accounts;*/ 

Balaji BondarBalaji Bondar
Hi Robert,
Please refer below link for test class creation for trigger.

Important :
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.
Robert WynterRobert Wynter
I think I might have something based on that link. Does the following make sense:
public with sharing class testUpdateAccountStatus {
    static testMethod void LogPersonAccountChangeTest() {
        Account account = new Account(Name='TEST AGENT ACCOUNT',Status__c='Active');
        System.debug('Status before inserting new Status: ' + account.Status__c);

       // Insert book

       insert account;
        // Retrieve the new book
        account = [SELECT Status__c FROM Account WHERE Id =:account.Id];
        System.debug('Status after trigger fired: ' + account.Status__c);
           // Test that the trigger correctly updated the price
      	   System.assertEquals('Active', account.Status__c);