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
test pawantest pawan 

How to write Test class for this Trigger

trigger TimeZone on Contact (before insert, before update) {

 for (Contact cc : Trigger.new)
 
 {
  if(cc.User_Place_Time_Zone__c =='GMT+05:30')
  {
   if(CC.Customer_Place_Time_Zone1__c=='GMT+01:00')
    {
     cc.Customer_Place_Time__c = System.Now()- (0.1875);
    }
   if(CC.Customer_Place_Time_Zone1__c=='GMT+02:00')
    {
     cc.Customer_Place_Time__c = System.Now()- (0.14583);
    }
   if(CC.Customer_Place_Time_Zone1__c=='GMT+03:00')
    {
     cc.Customer_Place_Time__c = System.Now()- (0.1042);
    }

}

}

skodisanaskodisana

Hi,

 

Try the below code:

 

@isTest
Private class TestClass_Contact
{
    public static testmethod void testContact()
    {
Contact con =new Contact(LastName='TestContact');
insert con;
Contact coUpdat = new Contact(Id=con.Id,LastName='TestContactUpdate');
update coUpdat;

}