Sample Trigger:
trigger AccountTrigger on Account ( before insert, before update ) {
for ( Account objAcc : trigger.new ) {
if ( String.isNotBlank( objAcc.Description ) ) {
objAcc.Description = objAcc.Description.replace( ‘,’, ‘n’ );
}
}
}
Test Class for the Trigger:
@isTest
public class AccountTriggerTest {
static testMethod void acctInsertTest() {
Account objAcc = new Account( Name = ‘Testing’, Description = ‘A,B’ );
insert objAcc;
objAcc = [ SELECT Description FROM Account WHERE Id =: objAcc.Id ];
System.assertEquals( objAcc.Description, ‘AnB’ );
}
}
@isTest
public class AccountTriggerTest {
static testMethod void acctInsertTest() {
Account objAcc = new Account( Name = ‘Testing’, Description = ‘A,B’ );
insert objAcc;
objAcc = [ SELECT Description FROM Account WHERE Id =: objAcc.Id ];
System.assertEquals( objAcc.Description, ‘AnB’ );
}
}
Output: