You need to sign in to do that
Don't have an account?
Testing apex trigger
Hello,
I recently tried deploying a change set from my sandbox to a production org (trigger as follows):
trigger AutoCreateRecord on Account (after insert) {
List<Record__c> Record= new List<Record__c>();
//For each Account record created, add a new record
//Note that Trigger.New is a list of all the new records
for (Account newAccount: Trigger.New)
{
if(
newAccount.ispersonAccount == True &
newAccount.Record_Required__c == True)
{
Record.add(new Record__c(Customer_name__c = newAccount.Id, Record_Status__c = 'Sent'));
}
}
insert Record;
}
This has worked well in the sandbox. However, I have since learned that I need to obtain test coverage of 75% of more for it to be used in production. I am new to apex and do not know how to do this. Any ideas would be appreciated, as the guides I've seen have been a bit beyond me!
Thanks!
HI XJC,
Here is the test class for your trigger:-
@isTest
public class AutoCreateRecord_Test{
public static testmethod void methodname() {
Account a=new Account();
A.name='test';
A.Record_Required__c=True;
A.ispersonAccount = True;
insert a;
Record__c r=new Record__c();
r.Customer_name__c=a.id;
r. Record_Status__c='sent';
insert r;
}
}
Hello Anil.B
Thank you for your post and for providing me with this.
The only mystery which remains for me is how do I actually test it? Also, if anyone can explain what this test actually does, I'd very much appreciate it, as I have a long way to go before mastering apex! :)
Thanks!!
Hi
After wirting the above class and save it you can find a run test button after saving the class run it .
Then it show up wether the test class is passed or fail .If it passed then no issues.
Lookup for the code Coverage by clicking up developer console button and see the code coverage for your trigger.
Its should be more than 75%.if its less try to increase the code coverage .