You need to sign in to do that
Don't have an account?
Apex Test Coverage problem
trigger Dummy on Account (before insert)
{
for (Account a : Trigger.new)
{
String Card = '';
String tempAccount = a.Name;
String tempBllStreet = a.BillingStreet;
String tempPstlCode = a.BillingPostalCode;
If(tempAccount != null)
{
tempAccount = tempAccount.toUpperCase();
tempAccount = tempAccount.replaceAll('[\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\x7f\\x80-\\xfe]','');
String AccountName = tempAccount;
if(tempAccount.length() > 5)
AccountName = tempAccount.substring(0,5); Card = AccountName;
}
If(tempBllStreet != null)
{
tempBllStreet = tempBllStreet.toUpperCase();
tempBllStreet = tempBllStreet.replaceAll('[\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\x7f\\x80-\\xfe]','');
String BillingStreet = tempBllStreet;
if(tempBllStreet.length() > 4)
BillingStreet = tempBllStreet.substring(0,4);
Card = Card + BillingStreet;
}
If(tempPstlCode != null)
{
tempPstlCode = tempPstlCode.toUpperCase();
tempPstlCode = tempPstlCode.replaceAll('[\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\x7f\\x80-\\xfe]','');
String PostalCode = tempPstlCode;
if(tempPstlCode.length() > 6)
PostalCode = tempPstlCode.substring(0,6);
Card = Card + PostalCode;
}
If(Card != '')
a.CardCode__c = Card;
else
a.CardCode__c = a.Name;
}
}
and my apex class for test coverage is as follows
public class AccountTest
{
static testMethod void myTest()
{
Account[] a = new Account[]{new Account(Name = 'Dave',BillingStreet = 'MyStreet1',BillingPostalCode = '123456'),
new Account(Name = null,BillingStreet = 'MyStreet2',BillingPostalCode = '123457'),
new Account(Name = 'Dave',BillingStreet = null,BillingPostalCode = '123456'),
new Account(Name = 'Dave',BillingStreet = null,BillingPostalCode = null)};
insert a;
}
}
can any one of pls help me.
Message Edited by Sampath on 04-22-2008 10:29 PM
To execute your Account trigger, you'll need to insert an Account within a test method. (DML statements executed inside test methods are not committed, so your production data will not be altered.)
Once you've written suitable tests to meet or exceed the code coverage minimums, you will want to deploy your trigger and the class(es) containing its test methods all at once.
See the Apex Code documentation for details.
I saw your response to this posting, and I'm hoping you might be able to help me, I'm new to Apex.
I have a very simple lookup-field trigger that places a record ID in that field, on a custom "Accounts" object, not the standard object:
trigger SetAccountField on Account__c (before insert, before update) {
for (Account__c Account__c : Trigger.new) {
a.Scoring__c = 'a00A0000003MnLw';
}
}
How can I create a test class, for something like this? Can you give me an example of the best way to test something this simple?