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
jsacpt24jsacpt24 

Help on trigger if/else trigger - 70%

Trigger:
trigger AccountTrigger on Account (before update)
  {
  
  if(checkRecursive.runOnce())
    {
    list<Account> account_Updatelist= new list<Account>();
    for(Account acc : Trigger.new)
      {
       
         if(acc.Total_Opportunities_Won__c>=1 && acc.Active_Opportunities__c == 0 && Trigger.oldMap.get(acc.id)!=null && Trigger.oldMap.get(acc.id).Active_Opportunities__c>=1)
            acc.Account_Clearing_Date__c= system.today();
            
         else if(acc.Total_Opportunities_Won__c>=1 && acc.Active_Opportunities__c >= 1)
             acc.Customer_Type__c = 'Current Client';
             
          else if(acc.Total_Opportunities_Won__c==0 && acc.Active_Opportunities__c==0)
             acc.Customer_Type__c = 'Prospect';
             
          
            
      }
      
          
      }
          
   }

Test Class: 
@isTest
private class testAccountTrigger {

static testMethod void customerTypeTest(){
    
    /*Create Account*/
    Account acc1=new Account();
    acc1.Name='Test Account1';
    acc1.Account_Status__c='Active';
    acc1.OMC_Alliance__c=true;
    insert acc1;
    
    /*Create Opportunity*/
    Opportunity opp1=new Opportunity();
    opp1.Name='Test Opportunity1';
    opp1.AccountId=acc1.Id;
    opp1.closeDate=date.today();
    opp1.stageName='Proposal';
    opp1.Type='Net New Account - First Deal';
    opp1.Project_Type_2__c='Data & Analytics';    
    opp1.Call_Center_Country__c='U.S.';
    opp1.Televerde_Ownership__c='Televerde U.S.';
    insert opp1;
    
    /*Create CDP*/
    Campaign_Design_Profile__c cdp1= new Campaign_Design_Profile__c();
    cdp1.name='Test CDP1';
    cdp1.Campaign_Type__c='Lead Generation';
    cdp1.Related_Opportunity__c=opp1.Id;
    cdp1.CDP_Status__c='new';
    cdp1.Account_Name_Ref__c=acc1.Id;
    cdp1.Volume__c=1324;
    cdp1.Estimate_Type__c='FTEs';
    cdp1.of_Hours__c=7500;
    cdp1.Requested_Start_Date__c=date.today();
    cdp1.Requested_Completion_Date__c=date.today(); 
    insert cdp1;
        
  opp1.StageName='closed won';
    update opp1;
    
    cdp1.CDP_Status__c='Completed';
    update cdp1;}
    
static testMethod void customerTypeTest1(){
    
    /*Create Account*/
    Account acc2=new Account();
    acc2.Name='Test Account2';
    acc2.Account_Status__c='Active';
    acc2.OMC_Alliance__c=true;
    insert acc2;
    
    /*Create Opportunity*/
    Opportunity opp2=new Opportunity();
    opp2.Name='Test Opportunity2';
    opp2.AccountId=acc2.Id;
    opp2.closeDate=date.today();
    opp2.stageName='Proposal';
    opp2.Type='Net New Account - First Deal';
    opp2.Project_Type_2__c='Data & Analytics';    
    opp2.Call_Center_Country__c='U.S.';
    opp2.Televerde_Ownership__c='Televerde U.S.';
    insert opp2;
    
    /*Create CDP*/
    Campaign_Design_Profile__c cdp2= new Campaign_Design_Profile__c();
    cdp2.name='Test CDP2';
    cdp2.Campaign_Type__c='Lead Generation';
    cdp2.Related_Opportunity__c=opp2.Id;
    cdp2.CDP_Status__c='new';
    cdp2.Account_Name_Ref__c=acc2.Id;
    cdp2.Volume__c=1324;
    cdp2.Estimate_Type__c='FTEs';
    cdp2.of_Hours__c=7500;
    cdp2.Requested_Start_Date__c=date.today();
    cdp2.Requested_Completion_Date__c=date.today(); 
    insert cdp2;
    
    }
}



The items not being covered are: 
else if(acc.Total_Opportunities_Won__c==0 && acc.Active_Opportunities__c==0) acc.Customer_Type__c = 'Prospect';

as well as 
acc.Account_Clearing_Date__c= system.today();

Am I supposed to have a secondary static test in this? When I tried what I thought I needed to do it gave me the same code coverage. 
Shivdeep KumarShivdeep Kumar
Hi,
You are using the trigger on account and there there is no other object like opportunity and CDP , May be I am wrong about my understanding.
Pease try below code and try to get some idea from this test class !
 
@isTest
private class testAccountTrigger {

	static testMethod void customerTypeClient(){
		
		/*Create Account*/
		Account acc1=new Account();
		acc1.Name='Test Account1';
		acc1.Account_Status__c='Active';
		acc1.OMC_Alliance__c=true;
		acc.Total_Opportunities_Won__c = 1;
		acc.Active_Opportunities__c = 1;
		insert acc1;
		
	}    
	static testMethod void Prospectdata(){
		
		/*Create Account*/
		Account acc2=new Account();
		acc2.Name='Test Account2';
		acc2.Account_Status__c='Active';
		acc2.OMC_Alliance__c=true;
		acc.Total_Opportunities_Won__c = 0;
		acc.Active_Opportunities__c = 0;
		insert acc2;
		
	  
	}
		
	static testMethod void Clearing_DateData(){
		
		/*Create Account*/
		Account acc2=new Account();
		acc2.Name='Test Account2';
		acc2.Account_Status__c='Active';
		acc2.OMC_Alliance__c=true;
		acc.Total_Opportunities_Won__c = 1;
		acc.Active_Opportunities__c = 0;
		insert acc2;
		
		acc2.Account_Clearing_Date__c= system.today();
		update acc2;
	  
	}
}

Thanks
Shivdeep​