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
sai_kumar_sfdc1.3903397698928884E12sai_kumar_sfdc1.3903397698928884E12 

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')
      {
      system.debug('$****************:'+opp.StageName+'::');
String wonOppId=opp.id;
List<OpportunityContactRole> availablecontacts = [SELECT Id, ContactId, OpportunityId from OpportunityContactRole where OpportunityId = :wonOppId AND IsPrimary=true];
if (availablecontacts.size()==0) return;
system.debug('$****************:'+availablecontacts[0].contactId+'::');

String primarycontactId=availablecontacts[0].contactId;

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




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

system.debug('$****************:'+availablecontact[0].Email+'::');
String sendemailto=availablecontact[0].Email;
opp.Primary_Contact_Email__c=sendemailto;

}
}
}

}
__
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.