• Sampath
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi,
     Am new to salesforce apex code.
 I wrote a trigger in sandbox login it was working fine. But when i put in the production it is throwing error like "Test coverage of selected Apex Class and Trigger is 0%, at least 75% test coverage is required"
 
 My trigger is a before insert trigger.
 
 Its logic is to fetch substring of Account name, billstreet and postal code and add them and put it in the new custom field.
 
Can anyone of help me to find what is the problem in my apex trigger and class.
 
 My trigger is as follows.

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
Hi,
     Am new to salesforce apex code.
 I wrote a trigger in sandbox login it was working fine. But when i put in the production it is throwing error like "Test coverage of selected Apex Class and Trigger is 0%, at least 75% test coverage is required"
 
 My trigger is a before insert trigger.
 
 Its logic is to fetch substring of Account name, billstreet and postal code and add them and put it in the new custom field.
 
Can anyone of help me to find what is the problem in my apex trigger and class.
 
 My trigger is as follows.

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