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
XJCXJC 

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!

@anilbathula@@anilbathula@

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;
}
}

XJCXJC

Hello 

 

 

@anilbathula@@anilbathula@

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 .