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
Andrew Fisher 28Andrew Fisher 28 

help with test class please!_

Can anyone help me with a Test class for this code please ?

Apex Class
public class OpptyCloseTimerCntrl {
    
    @AuraEnabled
    public static Date fetchOpptyCloseDate(String recId){
        Opportunity opp = [select End_of_Quarter__c from Opportunity where id =: recId];
        system.debug('Close Date: ' +opp.End_of_Quarter__c);
        
        return opp.End_of_Quarter__c;
    }
}
Best Answer chosen by Andrew Fisher 28
CharuDuttCharuDutt
Hii Andrew
Try Below Test Class
@isTest
	public Class OpptyCloseTimerCntrlTest(){
@isTest
		public static void UnitTest(){
		Opportunity opp = new opportunity();
		Opp.Name = 'Test Opp';
		Opp.StageName = 'Closed Won';
		Opp.ClosedDate = System.TOday();
		Opp.End_of_Quarter__c = /*Fill This*/
		insert opp;
		
		OpptyCloseTimerCntrl.fetchOpptyCloseDate(opp.Id);
		
		}
}
Please Mark It As Mark it As Best Answer If It Helps
Thank You!

All Answers

CharuDuttCharuDutt
Hii Andrew
Try Below Test Class
@isTest
	public Class OpptyCloseTimerCntrlTest(){
@isTest
		public static void UnitTest(){
		Opportunity opp = new opportunity();
		Opp.Name = 'Test Opp';
		Opp.StageName = 'Closed Won';
		Opp.ClosedDate = System.TOday();
		Opp.End_of_Quarter__c = /*Fill This*/
		insert opp;
		
		OpptyCloseTimerCntrl.fetchOpptyCloseDate(opp.Id);
		
		}
}
Please Mark It As Mark it As Best Answer If It Helps
Thank You!
This was selected as the best answer
Andrew Fisher 28Andrew Fisher 28
Hi Charu, 
Your a superstar many thanks !
I made a slight amend to it as the End of Quarter is a formula field, but you got me on the right track !

@isTest
    public Class OpptyCloseTimerCntrlTest{
@isTest
        public static void UnitTest(){
        Opportunity opp = new opportunity();
        Opp.Name = 'Test Opp';
        Opp.StageName = 'Closed Won';
        Opp.CloseDate = System.TOday();
        
        insert opp;
        
        OpptyCloseTimerCntrl.fetchOpptyCloseDate(opp.Id);
        
        }
}
Thanks so much, now 100% Coverage :)