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
nilesh walkenilesh walke 

i want a test class on it

 public static void Validation(List<contact> con6){
        //   Opportunity opp= new opportunity();
        for(contact con:con6){
            for(opportunity oppt:[select id, name, amount from opportunity limit 10]){
                if(oppt.Amount<5000 || Oppt.Amount==null){
                    oppt.Amount=5000;
                    oppt.name=oppt.Name +'KING';
                }
                else{
                    oppt.Amount=oppt.Amount+1000;
                    oppt.Name='Dr'+oppt.Name;       
                } 
                Update oppt;
            }
        }
 
Best Answer chosen by nilesh walke
CharuDuttCharuDutt
Hii Nilesh Walke
Try Below Code
@isTest
public class unitest {
  @isTest
    public static void unittest(){
     list<Opportunity> lstOpp = new list<Opportunity>();   
     list<Contact> lstCon = new list<Contact>();
        for(integer i=0;i<5;i++){
            Contact Con =new Contact();
            Con.LastName = 'Test '+i;
            lstCon.add(Con);
            
            Opportunity Opp = new Opportunity();
        Opp.Name = 'test '+i;
        Opp.Amount = 4500;
            Opp.StageName ='Closed Won';
            Opp.CloseDate = system.today();
            lstOpp.add(Opp);
        }
        insert lstCon;
        insert lstOpp;
        test2.Validation(lstCon);
    }

}
Please Mark It As Best Answer If it Helps
Thank You!