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

Difficulty getting test coverage on a trigger



I'm fairly new to SalesForce and am working on some test code to get familiar with the platform. At present, I have created two custom classes (Payment__c and Project__c) and modified an existing class (Contact) successfully. Now I am attempting to create a trigger on Payment__c such that when it is modified (instert, update, delete) it will modify fields on the Project__c and Contact objects.


Note that Payment__c contains a Currency field named amount, a reference to a Project__c object and a reference to a Contact object. The trigger is supposed to update fields in the Project__c and Contact objects when a payment is inserted, updated, or deleted.


My trigger is very simple:


trigger ModifyPaymentToProject on Payment__c (after insert) {


 The class PaymentAction:


public with sharing class PaymentAction {
	public static void modifyPayment(List<Payment__c> payments) {
		for (Payment__c payment : payments) {
			// Do something here

 And I have a test for this PaymentTest:


private with sharing class PaymentTest {
	static testMethod public void paymentTest() {
		Project__c project = new Project__c();
		insert project;
		Contact contact = new Contact();
		contact.FirstName = 'me';
		contact.LastName = 'myself';
		contact.Email = ''; 
		insert contact;
		Decimal testAmt = 50.00;
        		Payment__c payment = new Payment__c(Project__c = project.Id, 				Contact__c = contact.Id, Amount__c = testAmt);
        		insert payment;
        		System.assertEquals(payment.amount__c, testAmt);

General Info: I am currently using version 18 of the SalesForce app and working with Eclipse with the SalesForce plugin.


My test class (PaymentTest) is giving me a warning that it is saved locally, not to the server and my trigger is giving the warning 'Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required'


Running the tests from Eclipse or the browser produce the same results: 0% coverage for my Payment and PaymentAction classes. Does anyone have some suggestions as to what I should be doing here?






Best Answer chosen by Admin (Salesforce Developers) 

if your test class is only saved locally, then you cannot really run the test because that happens inside sfdc, not in the ide.

Try saving again and check the "Problems" tab in Eclipse to see why it did not save to the server.


Does the test class in thebrowser really look the same as in Eclipse? Maybe the relevant parts of it do just not exist in sfdc.