• DM_Tim
  • NEWBIE
  • 0 Points
  • Member since 2010

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

Hello,

 

I need to check to see when an opportunity is set to isWon and take a few actions on it and some other objects. I created a trigger that fires on all of the after events for opportunity and reads the isWon boolean on the list of incoming opportunity objects. OK, so far, so good. Now my problem is that I'm writing a test where I create an opportunity object but I need to set the isWon field. Apparently that is a read-only field. I tried setting the stageName to 'Closed/Won' but that didn't change the isWon field. How can I simulate the closing of an opportunity into the 'Closed/Won' state and set the isWon field?

 

Regards,

 

Tim

Hello,

 

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) {
	PaymentAction.modifyPayment(trigger.new); 
}

 

 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:

 

@isTest
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 = 'me@myself.com'; 
		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?

 

 

Regards,

 

Tim

Hello,

 

I need to check to see when an opportunity is set to isWon and take a few actions on it and some other objects. I created a trigger that fires on all of the after events for opportunity and reads the isWon boolean on the list of incoming opportunity objects. OK, so far, so good. Now my problem is that I'm writing a test where I create an opportunity object but I need to set the isWon field. Apparently that is a read-only field. I tried setting the stageName to 'Closed/Won' but that didn't change the isWon field. How can I simulate the closing of an opportunity into the 'Closed/Won' state and set the isWon field?

 

Regards,

 

Tim