• justinpauldavis10
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies

I'm having difficulty installing this trigger:

 

 

trigger SetAccountField on Account__c (before insert, before update) {
    for (Account__c Account__c : Trigger.new) {
        Account__c.Scoring__c = 'a00A0000003MnLw';
    }
 }

 

 

Essentially, it updates the lookup field Scoring__c on a custom object called Account.

 

I'm getting there error: Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required.

 

What additional code am I missing to facilitate test coverage?

 

Thanks for any help anyone might have

Hi all,

 

need your help...

 

i have the following trigger below,

 

trigger Sales_Manager_Trigger on BGB_Contract__c (before insert, before update) {

	Map <id,BGB_Contract__c> contracts = new Map <id, BGB_Contract__c>();

    for (BGB_Contract__c bgbContract : Trigger.new)
    {
		contracts.put(bgbContract.Renewal_Negotiators__c, bgbContract);
    }		   
	//Not to fire Trigger if user is equal to 'Sean Churchill'
	if (UserInfo.getName()<> 'Sean Churchill')

	{ 
		Map <Id, String> bseNameContractIdMap = new Map<Id, String>();
	   for(BGB_Sales_Employees__c bse: [select name from BGB_Sales_Employees__c where ID IN :contracts.keySet()]){
	   	bseNameContractIdMap.put(bse.name, bse.id);
	   }
	   
	   for(User u: [select ID from User where Name IN :bseNameContractIdMap.keyset()]){
	   	BGB_Contract__c contract = contracts.get(bseNameContractIdMap.get(u.name)); // this is the record that the triggered fired for, that matches your users name
	   	contract.sales_manager__c = u.id;
	   }
			
	}
}

 

 

 and i have written test code but cannot get it over the 75% test coverage but only able to get it to 70%... can any one help?

 

@isTest
private with sharing class Sales_Manager_Email_Test {

static testMethod void MyTestSalesManEma()
{
test.starttest(); 

    BGB_Contract__c testContractEmail = new BGB_Contract__c();
    
      
   
    testContractEmail.Account_Name__c = '0012000000SSw7l';
    testContractEmail.Feedback__c = 'Testing';
    testContractEmail.Renewal_Negotiators__c = 'a0H20000001oFrpEAE';
    testContractEmail.Contract_Spend__c = 110;   
    
    insert testContractEmail;
    
 	test.stoptest();  
    

}
}

 

 

I need to write some code to cover the code below as i not cover these lines: -

 

for(User u: [select ID from User where Name IN :bseNameContractIdMap.keyset()]){
	   	BGB_Contract__c contract = contracts.get(bseNameContractIdMap.get(u.name)); // this is the record that the triggered fired for, that matches your users name
	   	contract.sales_manager__c = u.id;

 Any help would be great...

 

Sean.

I am getting the error above.  The code is below. I have systematically removed all code from this trigger to try and pinpoint what is generating this error. This what is left and it still generates the error;

 

 

trigger UpdCnt on Account (after update) {
List<Contact> cnt = new List<Contact>();
}

Obviously this trigger does nothing.  If I take out the one line that's in there it will Save to the Server.  

 

Any suggestions?

 

Austin_Steve

 

 

 

Hi Everyone,


I'm trying to deploy my first Apex trigger to PRODUCTION but not pases the validation I only made the 69% of 75%.

I don't know what I'm missing.

First I check the user who's launched the trigger. Then if is not a administrator I call the method MyMethod in the class ThisClass, and I pass the values of the Orders table who has been changed.

The class is tested and is correctly deployed.

Thanks in advance.

The code --> :

trigger Order_UPDATE on Orders (before update) {

    string userrole = UserInfo.getUserRoleId(); --> Get UserRoleId
   
    if (userrole != 'Administrator'){   --> If is not administrator enter the IF
       
        Orders[] accs = Trigger.new; --> Get the values

        This_Class.MyMethod(accs);  --> Pass it to the method
   
    }

}

  • October 09, 2008
  • Like
  • 0
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