+ Start a Discussion

Need Test for Opp Trigger

Need help on creating Test class for below Class?
Urgent Help please on this

public class OpportunityUpdateEmailHelper{
public static void  updatePrimaryEmailtoOpportunity(List<opportunity> ops)
   for(opportunity opp:ops)
      if(opp.StageName=='Closed Won')
String wonOppId=opp.id;
List<OpportunityContactRole> availablecontacts = [SELECT Id, ContactId, OpportunityId from OpportunityContactRole where OpportunityId = :wonOppId AND IsPrimary=true];
if (availablecontacts.size()==0) return;

String primarycontactId=availablecontacts[0].contactId;

List<Contact> availablecontact = [SELECT Id, Email from Contact where Id = :primarycontactId];

if (availablecontact.size()==0) return;

String sendemailto=availablecontact[0].Email;


This should be a good start http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods

The whole idea is to simulate the app behavior on your test class. For example if your test class interacts with Account records, you need to create account records in your test class programmatically and then instantiate the class you are testing and call it's methods. 

Hope that helps.