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
Nishigandha JadhavNishigandha Jadhav 

Need To write test class for this trigger (Account_License_Type_del__c -(Formula Field))

trigger Contactid on Case (before  update) {         for(Case c:trigger.new){             if(c.Account_License_Type_del__c!=null){             c.ContactId='0035C00000I4gjl';                    }         } }


Note: Not covering inside if statement.

 
Raj VakatiRaj Vakati
First, an important change is removing the hard-coded contact id from the trigger .. please query the contact name and pass it  .. change your trigger as below 
 
trigger Contactid on Case (before  update) { 

		List<Contact> con = [Select Id from Contact where Name = 'YOURCONTACT NAME'];

		for(Case c:trigger.new){    
			if(c.Account_License_Type_del__c!=null){ 
				if(con.size()>0){
					c.ContactId=con[0].Id;  
				}
			}      
		}
	}


The second one .. you need to create a test class data so that case record will evaluate the  Account_License_Type_del__c  formula to true 
 
@isTest public class Contactid {

public static testmethod void testMethodExecution(){
    Account accoObj = new Account();
    accoObj.Name  = 'testAcc';
    accoObj.Location__c = 'testLocation';
    accoObj.Type = 'New Customer';
    accoObj.BillingCountry = 'United States';
	//insert data to meet conditions 
insert accoObj ; 

	Contact conObj = new Contact();
    conObj.FirstName = 'test';
    conObj.LastName = 'testLastname';
    conObj.AccountId = accoObj.Id;
    conObj.Email = 'abc@gmail.com';
insert conObj ; 

	Case caseObj = new Case();
    caseObj.ContactId = conObj.Id;
    caseObj.Status = 'Open';
    caseObj.Subject = 'TestSubject';
	//insert the data to meet the formual to true 
    caseObj.Description = 'TestDescription';
    insert caseObj ; 
	caseObj.Status='Closed';
	// insert the data to meet formual to true
	update caseObj ;

}

}