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

how to write test class for the below code ?

Profile userProfile = [SELECT Id FROM Profile WHERE Name='System Administrator'];
            user userRole = [SELECT id, name, FROM User WHERE like '% FAWS Technical Onboarding Manager%'];
       if((userProfile.Id != UserInfo.getProfileId())||(userRole.Id != userInfo.getUserRoleId())){  
            List<Specialist_Lead__c > slist = new List<Specialist_Lead__c >();
            set<Id> leadId = new set<Id>();    
            List<string> adteamtype = new List<string>();    
            for(Specialist_Lead__c  s:{
            slist = [select id, Lead__c, Additional_Team_Type__c 
                     from Specialist_Lead__c 
                     where Lead__c IN :leadId
                     and Additional_Team_Type__c IN :adteamtype];
            Map< String, Id > duplicateSpecialistMap = new Map< String, Id >();    
            for(Specialist_Lead__c s : slist){
                duplicateSpecialistMap.put(s.Additional_Team_Type__c, s.Id);        
            for(Specialist_Lead__c s:{
                Id duplicateSpecialistId = duplicateSpecialistMap.get(s.Additional_Team_Type__c);
                if(duplicateSpecialistId != null)
                   s.addError('This AdditionalTeamType is already existed with this Lead');            
Rory HibbertRory Hibbert
Have you read the Salesforce documentation on Unit Testing? I would recommend that you give the documentation a read, digest it, make an attempt at writing the unit test class and then post with specific questions. 

This is too broad to answer here, and short of posting the entire test class as an answer, there isn't much help people will give you that isn't in the docs