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
rajesh kumar 10rajesh kumar 10 

I Have a problem with my Test class with my trigger? can any one solve this?

Here is my Trigger

trigger accountApprovalSubmit on Account (after insert) {
   
   
     for (Account a : trigger.new) {
        if (a.RecordType_Name__c == 'Plant' && !a.BlockTrigger__c && (a.Plant_Type__c == 'New Plant' || a.Plant_Type__c == 'Normal Plant'))
        {
            Approval.ProcessSubmitRequest app = new Approval.ProcessSubmitRequest();
            app.setObjectId(a.id);
            Approval.ProcessResult result = Approval.process(app);
        }
        else {
                if (a.RecordType_Name__c == 'Plant' && (a.Plant_Business_Type__c == 'New construction')
                    && (a.plant_Type__c == 'potential plant')
                    && (a.status__c!='active') && (a.super_region__c=='EAME')
                    && (a.account_industry_type__c =='Power - Fossil'||a.account_industry_type__c =='O & G'))
                {
                    Approval.ProcessSubmitRequest app = new Approval.ProcessSubmitRequest();
                    app.setObjectId(a.id);
                    Approval.ProcessResult result = Approval.process(app);
                }
        }       
       
       

    }
   

}

and Below is my Test class



@isTest

public class TestAccountApprovalSubmit{
         public static testmethod void accountApprovalSubmit(){  
         RecordType rdObj = [Select Id from RecordType where Name = 'Plant' and SobjectType ='Account']; 
                           
             account a=new account();              
                a.Name='Sample';
                a.RecordTypeId = rdObj.Id;
                a.Plant_Business_Type__c = 'New construction';
                a.plant_Type__c = 'potential plant';
                a.status__c = 'inactive';
                a.super_region__c = 'EAME';
                a.account_industry_type__c='Power - Fossil';
                a.Country__c = 'INDIA';
                a.State__c = 'GOA';
                a.Address__c = 'USA';
                a.City__c = 'USA';
                a.Postal_Code__c = 'USA';
               
              
              Test.startTest(); 
              insert a;
              Test.stopTest();

     }     

}


The code is covering only 66%
so can any one please suggest me for better code coverage..
 

thanks in advance
Ankit AroraAnkit Arora
Writting a test class for a generic scenario is more easy, as digging into your code with custom fields is very difficult for any one. I can only suggest you here that you've to fulfil the if else condition in your test class. As what you've written can be your first method in test class, write another method which will false the if condition so it can enter the esle and so on. I hope that make sense.
Arunkumar RArunkumar R
@isTest

public class TestAccountApprovalSubmit{
         public static testmethod void accountApprovalSubmit(){  
         RecordType rdObj = [Select Id from RecordType where Name = 'Plant' and SobjectType ='Account']; 
                           
             account a=new account();              
                a.Name='Sample';
                a.RecordTypeId = rdObj.Id;
                a.Plant_Business_Type__c = 'New construction';
                a.plant_Type__c = 'potential plant';
                a.status__c = 'inactive';
                a.super_region__c = 'EAME';
                a.account_industry_type__c='Power - Fossil';
                a.Country__c = 'INDIA';
                a.State__c = 'GOA';
                a.Address__c = 'USA';
                a.City__c = 'USA';
                a.Postal_Code__c = 'USA';
               
              
              Test.startTest(); 
              insert a;
              Test.stopTest();

     }     
	 
	  public static testmethod void accountApprovalSubmit1(){  
         RecordType rdObj = [Select Id from RecordType where Name = 'Plant' and SobjectType ='Account']; 
                           
             account a=new account();              
                a.Name='Sample';
                a.RecordTypeId = rdObj.Id;
				a.RecordType_Name__c = 'Plant';
                a.Plant_Business_Type__c = 'New construction';
                a.plant_Type__c = 'New Plant';
                a.status__c = 'inactive';
                a.super_region__c = 'EAME';
                a.account_industry_type__c='Power - Fossil';
                a.Country__c = 'INDIA';
                a.State__c = 'GOA';
                a.Address__c = 'USA';
                a.City__c = 'USA';
                a.Postal_Code__c = 'USA';
               
              
              Test.startTest(); 
              insert a;
              Test.stopTest();

     }     

}