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
vfexp41vfexp41 

Test Class For Task Trigeer

HI,

         Can anyone give me test class for my below trigger, i can't understand how to start the test class for my trigger

     
trigger updatequotestatus on task (after insert, after update){
    set<Id> quoteIds = new set<Id>();
    list<quote__c> quotes = new list<quote__c>();
      for(task t:trigger.new){
   
       if(t.whatId!=null){

        if((t.whatid.getsobjecttype()==quote__c.sobjecttype)){
            quoteIds.add(t.whatId);
        }
      } 
    }
    for(quote__c q:[select StageName__c from quote__c where Id IN : quoteIds]){
        quote__c qt = new quote__c();
        qt.Id = q.Id;
        qt.StageName__c = 'Proposal Sent';
        quotes.add(qt);
    }
    if(quotes.size()>0){
        update quotes;
    }
}

Best Answer chosen by vfexp41
Vinit_KumarVinit_Kumar
Try below code :-

@IsTest(SeeAllData=false)
public class updatequotestatus_test
{
	static testmethod void MyUnitTest()
	{	
		// Create an Opportunity record
		Opportunity opp = new Opportunity(Name='TestOpp',CloseDate=System.today(),StageName='Prospecting');
		insert opp;
		
		// Create an Opportunity record
		Quote q = new Quote(Name='Test Quote',OpportunityId=opp.id);
		insert q;
		
		// Create an Task record to test your Trigger and relate it with the Quote created
		Task t = new Task(Name='Test Task',Priority='Normal',whatId=q.id,Subject='Call',Status='Not Started');
		insert t;
	}

}

If this helps,please mark it as best answer to help others :)