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
Suraj DemgundeSuraj Demgunde 

i want to write test class on below trigger plz help me

trigger Lead_Update on Lead (before insert,before update) {
    String dam ='';
    String jub='';
    String west1 ='';
    String west2 = '';
    String central = '';
    String Gcc = '';
    for(Lead lt : trigger.new){
        if(String.isNotBlank(lt.Dammam__c)){
           
            dam = 'Dammam\n';
           
        }  
        
        if(String.isNotBlank(lt.Jubail__c)){
          
            jub = 'Jubail\n';
           
        }
       
        if(String.isNotBlank(lt.West_North__c)){
            
            west1 = 'West North\n';
 
        }
       
        if(String.isNotBlank(lt.West_South__c)){
           
            west2 = 'West South\n';
           
        }
      
        if(String.isNotBlank(lt.Central_Region__c)){
           
            central = 'Central\n';
        }
       
        If(String.isNotBlank(lt.GCC__c)){
           
            Gcc = 'GCC';
        }
       
       lt.Region__c = dam+ jub+ west1+west2 +central +Gcc;
       
    }
 
}
 
Abdul KhatriAbdul Khatri
Here is the test class with 100% converage
 
@isTest
public class Lead_Update_test {
    
    static testMethod void leadInserttest(){
        Lead lt = new Lead();
        lt.Company = 'Test';
        lt.LastName = 'Test';
        
        lt.Dammam__c = '1';
        lt.Jubail__c = '1';
        lt.West_North__c =  '1';
        lt.West_South__c = '1';
        lt.Central_Region__c = '1';
        lt.GCC__c = '1';
            
        insert lt; 
        
        
        Lead ltafterUpdate = [SELECT Region__c FROM Lead WHERE Id = :lt.Id];
        system.assertEquals('Dammam Jubail West North West South Central GCC', ltafterUpdate.Region__c);
    }
}

 
Suraj DemgundeSuraj Demgunde
@Abudul bhai what is use of  '1' in above class
 
Suraj DemgundeSuraj Demgunde
line 22, column 12: Dependent class is invalid and needs recompilation:
 Class CaseUpdater : Method does not exist or incorrect signature: void isRunningTest() from the type test this error shown
Amit Chaudhary 8Amit Chaudhary 8
try below code
@isTest
public class Lead_Update_test{
    static testMethod void leadInserttest()
	{
        Lead lt = new Lead();
			lt.Company = 'Test';
			lt.LastName = 'Test';
			lt.Dammam__c = 'Dammam';
			lt.Jubail__c = 'Jubail';
			lt.West_North__c =  'West North';
			lt.West_South__c = 'West South';
			lt.Central_Region__c = 'Central';
			lt.GCC__c = 'GCC';
        insert lt; 
		
    }
}

Let us know if this will help you
 
Abdul KhatriAbdul Khatri
@Amit Chaudary
I never recommend having a test method without having assertion as this will always make it pass even the test method is failing. It is a not a best practise. But it is up to you what you speard.

@Suraj

Regarding having a value 1, you can choose anything you want. I just made it as you code was looking !ISBLANK, so you need something to make that true.

Regarding the issue with Dependent class you are sharing above, it seems like you need to check that class and properly save it. I don't think it has to do with this until you are doing anthing at the lead trigger level of calling that class for some reason. You just need making sure that class ClassUpdater compile without issues.
 
Abdul KhatriAbdul Khatri
Please let me know what you think.