+ Start a Discussion
kiran punurukiran punuru 

How to cover the lines after for loop

Hi All,

Can Someone tell me how to cover the lines of code inside for loop .
My Class is:

public with sharing class MyClass{
  public static void (String userId,List<String> oppids)(){
List<Opportunity> lstopp = new List<Opportunity>();
 for(Opportunity opp :[Select id ,name,Probability  from Opportunity where  Probability == 50]){
      if(opp.probability == 50){
          opp.probability = 65;
       lstopp.add(opp);
}
}
 
Bryan JamesBryan James
@isTest
public class MyClassTest {
    static testMethod void myTest() {
        List<Opportunity> oppList = new List<Opportunity>();
        Opportunity opp1 = new Opportunity(Name = 'opp1',Probability =50,CloseDate = System.today(),StageName ='ClosedWon');
        oppList.add(opp1);
        Opportunity opp2 = new Opportunity(Name = 'opp2',Probability =45,CloseDate = System.today(),StageName ='ClosedWon');
        oppList.add(opp2);
        
        insert oppList;
        
        
        MyClass.buildlstopp(UserInfo.getUserId(),new List<String>{'',''});
        
    }
}

That should cover the code based on the way it is written. Are you using the List of Strings and UserId in the method somewhere?