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
tzuvytzuvy 

Average test coverage across all Apex Classes is 74%, at least 75%

Hi,

 

I've written a couple of classes that should run on my production account in salesforce. I've finished my tests and everything works perfect. Now I'm trying to deploy the classes into my production account and get the following message in eclipse:


Average test coverage across all Apex Classes and Triggers is 74%, at least 75% test coverage is required    Cost Of Service        line 1    Force.com code coverage warning

 

When I run all tests in my prod account the average coverage on all classes is 82%.

 

The clas I'm trying to deploy has 74% coverage.

 

Here is the code of the first clas I'm trying to deploy:

 

 

I created a test class to bring the coverage from 2% to 74% but I'm obviously doing something wrong.

I would appreciate if someone could give me an example of how to write a test method for one of my methods so I can deploy this code.

 

Thanks

Tzuvy

tzuvytzuvy

Here is the class

global class sync_BatchChatLoader implements Database.Batchable<Sobject>, Database.AllowsCallouts, Database.Stateful
{

global Chat_Transcript_Export__c ChatTranscriptExport;
global Integer numberOfUpsertFails = 0;
global list <Chat_Details__c> chatsList = new list <Chat_Details__c>();





public sync_BatchChatLoader (Chat_Transcript_Export__c obj) {
 
    ChatTranscriptExport = obj;
}  



 
  global database.querylocator start(Database.BatchableContext BC){
    
    String query = 'Select a.id,a.ParentId, a.Name ,a.Body From Attachment a where ParentId = \'' + ChatTranscriptExport.Id+ '\'';
    
    return Database.getQueryLocator(query);
  }
 
  global void execute(Database.BatchableContext BC, Sobject[] scope){
    
    list<Attachment> attachmentList = new list<Attachment>();
      
          for(Attachment att : ((List<Attachment>) scope)){
            
            Dom.Document doc = new Dom.Document();
            doc.load(att.body.tostring());
            
            Dom.XMLNode report = doc.getRootElement();
            
            //for(Dom.XMLNode session : report.getChildElements())
            
            //For every session insert a chat.
            
            
            Integer sessionsNum = 200;
            Integer chunksNum = (report.getChildElements().size()/sessionsNum) + 1;
          
          for(Integer j=0; j < chunksNum; j++){
            
            Integer innerLoopCount = sessionsNum * j + sessionsNum;
            Integer innerIndex = j * sessionsNum;
            
            for(Integer i=innerIndex; i< innerLoopCount;i++){
                       
                       
                       Chat_Details__c chatInfo = new Chat_Details__c();
                       
                       
                try{
                       Dom.XMLNode session = report.getChildElements().get(i);              
                       Dom.Xmlnode VisitorNode = session.getChildElement('Visitor',null);
                       Dom.Xmlnode GeoInfoNode = VisitorNode.getChildElement('GeoInfo',null);
                       Dom.Xmlnode ChatNode = session.getChildElement('Chat',null);
                       Dom.Xmlnode VarValuesNode = session.getChildElement('VarValues',null);
                       Dom.Xmlnode Reps = session.getChildElement('Reps',null);
                       
                       chatsList.add (this.UpsertChatDetails(chatInfo, VisitorNode, GeoInfoNode, ChatNode, VarValuesNode, Reps, session));
                         
                  
                    }
                  catch(Exception e){
                    
                    //ChatTranscriptExport.Export_Log__c = ChatTranscriptExport.Export_Log__c + e.getMessage() + '\n<br/>';
                    continue;
                    }  
                         
                       
                   }
                       try{
                  upsert chatsList;
                    }
                  catch(Exception e){
                    numberOfUpsertFails++;
                    ChatTranscriptExport.Export_Log__c =ChatTranscriptExport.Export_Log__c + e.getMessage()+'\n<br/>';
                    continue;
                    }  
          }
          }
          
      ChatTranscriptExport.Failed_Imports__c = numberOfUpsertFails;
      upsert ChatTranscriptExport;
  }

  global void finish(Database.BatchableContext BC){
    
  }
 

tzuvytzuvy

/******************************  Public Methods  ********************************************/  
 public string GetLevel1(dom.xmlnode pNode){
     string value = '';
     String[] listOfVariables =  new String[] {'survey843403294','survey843403295',
                                                        'survey843403296',
                                                        'survey843403297',
                                                        'survey843403300',
                                                        'survey843403301',
                                                        'survey843403302',
                                                        'survey843403303',
                                                        'survey843403304',
                                                        'survey843403305',
                                                        'survey843403306',
                                                        'survey843403307',
                                                        'survey843403359',
                                                        'survey843403360',
                                                        'survey843403361',
                                                        'survey843403362',
                                                        'survey843403363',
                                                        'survey843403364',
                                                        'survey843403365',
                                                        'survey843403293'};
     
            for (Integer i = 0; i<=19; i++){
                
                if (!this.GetAttributeTextByAttributeName(pNode, 'name', listOfVariables[i]).equals('')){
                           value =  GetAttributeTextByAttributeName(pNode, 'name',listOfVariables[i]);
                           break;
                         }
                
            }
                                                        
        return value;
     
     
 }   
 
 

tzuvytzuvy

public string GetLevel2(dom.xmlnode pNode){
     string value = '';
     String[] listOfVariables =  new String[] {'survey843403314',
                                                'survey843403315',
                                                'survey843403316',
                                                'survey843403317',
                                                'survey843403318',
                                                'survey843403319',
                                                'survey843403320',
                                                'survey843403321',
                                                'survey843403322',  
                                                'survey843403323',
                                                'survey843403324',
                                                'survey843403325',
                                                'survey843403326',
                                                'survey843403327',
                                                'survey843403328',
                                                'survey843403329',
                                                'survey843403330',
                                                'survey843403331',
                                                'survey843403332',
                                                'survey843403333',
                                                'survey843403334',
                                                'survey843403335',
                                                'survey843403336',
                                                'survey843403337',
                                                'survey843403338',
                                                'survey843403339',
                                                'survey843403341',
                                                'survey843403340',
                                                'survey843403342',
                                                'survey843403343',
                                                'survey843403344',
                                                'survey843403346',
                                                'survey843403347',
                                                'survey843403348',
                                                'survey843403349',
                                                'survey843403350',
                                                'survey843403351',
                                                'survey843403352',
                                                'survey843403353',
                                                'survey843403354',
                                                'survey843403355',
                                                'survey843403356',
                                                'survey843403357',
                                                'survey843403366',
                                                'survey843403367',
                                                'survey843403368',
                                                'survey843403369',
                                                'survey843403370',
                                                'survey843403371',
                                                'survey843403372'};
     
            for (Integer i = 0; i<=49; i++){
                
                if (!this.GetAttributeTextByAttributeName(pNode, 'name', listOfVariables[i]).equals('')){
                           value =  GetAttributeTextByAttributeName(pNode, 'name',listOfVariables[i]);
                           break;
                         }
                
            }
                                                        
        return value;
     
     
 }   
  public string GetAccountIDbySiteID (Dom.Xmlnode pVarValuesNode){
    
    string pValue;
    List <Account> account = new List <Account>();
    
    if (!this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'Siteid').equals('')) {
           
           pValue = this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'Siteid');
           
            }else if (!this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'survey3301011').equals('')) {
            
                    pValue = this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'survey3301011');
        
                }else {
           
                              pValue = '1212121212';
                                    }
   
                
    try{
                account = [select   LPSiteID1__c, id, name, site from Account where LPSiteID1__c =:pValue];
                        
                        if (account.size()>0){
                          return (account.get(0)).Id;
                        
                                }else{
                                      
                                      return '001A000000HfTan';
                                        }
//return (account.get(0)).Id;
                                   }
    catch (Exception e){
              
              return '001A000000HfTan';
                        }
                    }
 
 
 
 
 

tzuvytzuvy

public Chat_Details__c UpsertChatDetails (Chat_Details__c pChatInfo, Dom.Xmlnode pVisitorNode, Dom.Xmlnode pGeoInfoNode, Dom.Xmlnode pChatNode, Dom.Xmlnode pVarValuesNode, Dom.Xmlnode pReps, Dom.Xmlnode session){
         
         if(this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'origin').contains('SSO')){
                               
                               
                               pChatInfo.Account_del__c= this.GetAccountIDbySiteID(pVarValuesNode);
                               pChatInfo.Chat_Is_SSO__c = true;
                               pChatInfo.SSO_Identifier__c = this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'identifier');
                               pChatInfo.Packages__c = this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'Packages');
                               pChatInfo.SSO_LoginStatus__c=this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'LoginStatus');
                               pChatInfo.SSO_User_Email_Address__c = this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'UserEmailAddress') ;
                               pChatInfo.SSO_User_Login_Name__c = this.GetAttributeTextByAttributeName(pVarValuesNode, 'name',  'UserLoginName');
                               pChatInfo.SSO_OEM__c = this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'accountOEM') + this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'OEM');
                               pChatInfo.SSO_Number_of_Seats__c = this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'NumOfSeats');
                               pChatInfo.UserPermissionLevel__c = this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'UserPermissionLevel');
                               pChatInfo.SSO_Rep_Version__c = this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'UserVersion');
                               pChatInfo.Customer_Subscription__c = this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'ServiceType');
                               pChatInfo.SSO_Server_Name__c= this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'ServerName');
                               pChatInfo.SSO_Server_Domain__c = this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'ServerDomain');
                               pChatInfo.SSO_Server_Version__c = this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'ServerVersion');
                               
                           if (pChatInfo.SSO_OEM__c != null){    
                               if (pChatInfo.SSO_OEM__c.length() >= 4){
                                   
                               pChatInfo.SSO_OEM__c = pChatInfo.SSO_OEM__c.substring(0,2);
                               }
                           }
                           
                           if (pChatInfo.SSO_Rep_Version__c != null){
                               
                               if ( pChatInfo.SSO_Rep_Version__c.length() >= 24){
                                   
                               pChatInfo.SSO_Rep_Version__c = pChatInfo.SSO_Rep_Version__c.substring(0, pChatInfo.SSO_Rep_Version__c.indexOf(' '));
                                   
                               }
                           }
                           
                           if (pChatInfo.Customer_Subscription__c != null){
                               if (pChatInfo.Customer_Subscription__c.equals('ProContactCenterVoicePlus')){
                                   pChatInfo.Customer_Subscription__c = 'LivePerson Contact Center Plus';}
                                   
                                   else if(pChatInfo.Customer_Subscription__c.equals('Pro')){
                                   pChatInfo.Customer_Subscription__c = 'LivePerson Pro (Original)';}
                              
                                  else if(pChatInfo.Customer_Subscription__c.equals('ProContactCenter')){
                                   pChatInfo.Customer_Subscription__c = 'LivePerson Contact Center Standard';}
                                  
                                  else if(pChatInfo.Customer_Subscription__c.equals('ProContactCenterPlus')){
                                   pChatInfo.Customer_Subscription__c = 'LivePerson Contact Center Standard Plus';}
                                 
                                 else if(pChatInfo.Customer_Subscription__c.equals('ProContactCenterVoice')){
                                   pChatInfo.Customer_Subscription__c = 'LivePerson Contact Center';}
                                  
                                  else if (pChatInfo.Customer_Subscription__c.equals('ProPlus')){
                                   
                                   pChatInfo.Customer_Subscription__c = 'LivePerson Pro Plus';}
                               }
                                  //else {
                                      //pChatInfo.Customer_Subscription__c = pChatInfo.Customer_Subscription__c ;
                                      
                                  //}
                                                                                            
                               }
                                   
                                   else{pChatInfo.Account_del__c= this.GetAccountIDbySiteID(pVarValuesNode);     
                                       
                                       }    

tzuvytzuvy

   pChatInfo.Chat_Origin__c = this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'origin');
               pChatInfo.Chat_Lines__c = pChatNode.getChildElements().size();                    
            pChatInfo.SSO_Identifier__c = this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'identifier');           
               pChatInfo.Chat_Session_ID__c = session.getAttribute('id', null);
               pChatInfo.VI_Country__c = pGeoInfoNode.getChildElement('geoCountry', null).getText();
               pChatInfo.VI_IP_Address__c = pGeoInfoNode.getChildElement('geoIP', null).getText();
               pChatInfo.VI_City__c = pGeoInfoNode.getChildElement('geoCity', null).getText();
               pChatInfo.VI_State_Province__c = pGeoInfoNode.getChildElement('geoReg', null).getText();
               pChatInfo.VI_ISP__c = pGeoInfoNode.getChildElement('geoISP', null).getText();
               pChatInfo.Name = 'Chat Detail For Session:'+ ' '+pChatInfo.Chat_Session_ID__c;
               pChatInfo.Ticket_Number__c = this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'Ticket');
               pChatInfo.Skill__c = this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'skill');
               pChatInfo.Visitor_Site_ID__c = this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'Siteid')+ this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'survey3301011');
               pChatInfo.Chat_Operator__c = this.GetLastAttributeTextByAttributeName(pReps, 'order','0');
               pChatInfo.Chat_Start_Time__c = this.GetDateTime(pChatNode.getAttribute('start_time', null));
               pChatInfo.Chat_End_Time__c = this.GetDateTime(pChatNode.getAttribute('end_time', null));
               pChatInfo.Chat_Content_URL__c = 'https://';
               pChatInfo.Auditing_Options__c = this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'survey442203181');
               
               pChatInfo.Exit_Survey_Issue_Resolved__c = this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'survey4369024');
                   
                   if (pChatInfo.Exit_Survey_Issue_Resolved__c != null){              
                       if (!(pChatInfo.Exit_Survey_Issue_Resolved__c.equals(''))){
                       
                                   pChatInfo.Exit_Survey__c = this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'survey7058023');
                                   pChatInfo.Exit_Survey_Rep_Rate__c = this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'survey6737021');
                       }
                   }
                              
               pChatInfo.Chat_Disposition__c= this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'survey0076032');
               
               if (pChatInfo.Chat_Disposition__c != null){    
                   
               if (pChatInfo.Chat_Disposition__c.equals('Resolved (No Escalation)')){
                     
                     pChatInfo.Reason__c= this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'survey843403289');
                     pChatInfo.Core_Component__c= this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'survey843403290')+this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'survey843403291')+this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'survey843403292')+this.GetAttributeTextByAttributeName(pVarValuesNode, 'name', 'survey843403358');
                     pChatInfo.Level_1__c = this.GetLevel1(pVarValuesNode);
                     
                     if (pChatInfo.Level_1__c != null){    
                         if (!(pChatInfo.Level_1__c.equals(''))){
                                 
                                 pChatInfo.Level_2__c = this.GetLevel2(pVarValuesNode);
                                 
                            }
                     }
                }
               }
                   
                                                                                   
                         
                                 
               
               return pChatInfo;
                       
            
          }
          
      
    }

d3developerd3developer

Usually the problem is that you aren't deploying one of the classes with the test code over to the new org (not everything is included in a package by default).

Jitendra RanaJitendra Rana
Select *fast Deployment* to bypass running all the tests.