function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ashu 6112ashu 6112 

test class_help

I have this trigger, need to write test class for this: 
Please help.

trigger AccountInitiationDate on Account (before insert) {
    List<Account> lstacc = new List<Account>();
    for(Account account : trigger.new){
        //if(account.Initiation_Date__c==null){
                account.Initiation_Date__c=System.today();
                account.Approval_Date__c=null;
                account.Status__c='Draft';
                lstacc.add(account);
            System.debug('AccountInitiationDate Initiated ');
        //}
    }
}
Greg CooganGreg Coogan
You are your best resource. I self-taught myself Apex, but also had the help of Trailhead and developer documentation. Try learning from these resources:

https://developer.salesforce.com/page/How_To_Test_Your_Apex_Triggers
https://trailhead.salesforce.com/modules/apex_testing/units/apex_testing_intro

There are also plenty of existing posts on here about writing test classes.
Amit Chaudhary 8Amit Chaudhary 8
Please check below post to learn about test classes with sample code
1) http://amitsalesforce.blogspot.com/search/label/Test%20Class
2) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
3) https://developer.salesforce.com/page/How_To_Test_Your_Apex_Triggers

Trailhead is best way to learn
1) https://trailhead.salesforce.com/modules/apex_testing/units/apex_testing_intro

To Create the test class for Trigger you need to follow below step
1) Create Test Data in your case you need to create Account data

Like below
@isTest 
public class AccountInitiationDateTest 
{
    static testMethod void testMethod1() 
	{
		Account testAccount = new Account();
			testAccount.Name='Test Account' ;
		insert testAccount;
		
		
    }
}
Let us know if this will help you