+ Start a Discussion
Amol PrachetaAmol Pracheta 

I want test class on below class.


public class ApplyDiscount{

public static void insertdiscount(List<opportunity> opplist){
    for(Opportunity oa: opplist){
      if(oa.IsDiscountApplied__c != True)
     { oa.Amount= oa.Amount - oa.Amount*(0.1);
       oa.IsDiscountApplied__c=True;
      }          
   }
    }
}
Asma SalesforceAsma Salesforce
Hi All,

Can you please tell me how I can post a question on this website?
I am not able to find it please help me.
Thank You
CharuDuttCharuDutt
Hii Anmol
Try Below Test Class
@isTest
public class ApplyDiscounttest{
@isTest
public static void unitTest(){
list<opportunity> lstOpp = new list<opportunity>();
Opportunity opp = new Opportunity();
opp.Name = 'testOpp';
opp.ClosedDate = System.Today();
oppStageName = 'Closed Won';
opp.IsDiscountApplied__c = false;
opp.Amount = '1000';
lstopp.add(opp);
insert lstopp;
ApplyDiscount.insertdiscount(lstOpp);
}
}
Please Mark It As Best Answer If It Helps
Thank You!
Suraj Tripathi 47Suraj Tripathi 47
Hi Amol Pracheta,
 
@isTest
public class ApplyDiscounttest{
    @isTest
    public static void unitTest(){
        list<opportunity> ListOpp = new list<opportunity>();
        Opportunity opp = new Opportunity();
        opp.Name = 'testOpp';
        opp.CloseDate = System.Today();
        opp.StageName = 'Closed Won';
        opp.IsDiscountApplied__c = false;
        opp.Amount = 1000;
        ListOpp.add(opp);
        insert ListOpp;
        ApplyDiscount.insertdiscount(ListOpp);
    }
}


I hope you find the above solution helpful. If it does, please mark it as the Best Answer to help others too.
Thanks and Regards,
Suraj Tripathi