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

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')
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

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.