• Nikita Kapratwar
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies
global class MonthlyMatterInactive 
{
    global static String monthlyMatterInactive() 
    {
        Map<Id,Monthly_Matter_Execution__c> mmeMap = new Map<Id,Monthly_Matter_Execution__c>( [SELECT Id, Date_Executed__c from Monthly_Matter_Execution__c where Date_Executed__c = LAST_MONTH] );
        if(mmeMap.size() != 0)
        {
            list<matter__c> matter= [Select Id, OwnerId, Client__c, Prospect__c, Billing_RateLU__c from Matter__c where Consultation_Matter__c = TRUE and Set_Inactive__c = FALSE Order By CreatedDate DESC Limit 2];
            
            matter__c previousMatter =matter[1];
            
            if(previousMatter != null)
            {
                Matter__c previousMatterUpdate = new Matter__c();
                previousMatterUpdate.Id = previousMatter.Id;
                previousMatterUpdate.Set_Inactive__c = TRUE;
                Update previousMatterUpdate;
            }
        }
        return null;
    }
}



test class with 36% code coverage :

@istest
public class MonthlyMatterInactiveTest
{
    @istest  
    public static void testMethod2() {
        // code_block    
        // 
        test.startTest();
        Account acct = new Account(
            FirstName='test rohini',
            LastName='test twopir'
        ); 
        insert acct;
        
        Propsect__c prop =new Propsect__c(
            Spouses_First_Name__c='test',
            Spouses_Name__c='test',Person__c=acct.id);
        insert prop;
        

        list<matter__c> matter= new list<matter__c>();
        // matter.add(mat);
        
        Matter__c mattercObj = new Matter__c (
            Client__c = acct.id,  
            Prospect__c = prop.id,
            Status__c = 'Active',
            Type__c = 'Consultation',
            Apply_Fixed_Fee__c = FALSE,
            Fixed_fee_Amount__c = NULL,
            Send_Invoices_By__c = 'Mail',
            Apply_Interest__c = FALSE,
            Set_Inactive__c=False,
            Refresher_Amount__c=2345,
            Refresher_Required__c=true,
            Name='Consultations - Non Retainer ',   
            Consultation_Matter__c=True
        );
        matter.add(mattercObj);
        insert(matter);
        
        MonthlyMatterInactive.monthlyMatterInactive();
        test.stopTest();
    }       
    
}
global class MonthlyMatterInactive 
{
    global static String monthlyMatterInactive() 
    {
        Map<Id,Monthly_Matter_Execution__c> mmeMap = new Map<Id,Monthly_Matter_Execution__c>( [SELECT Id, Date_Executed__c from Monthly_Matter_Execution__c where Date_Executed__c = LAST_MONTH] );
        if(mmeMap.size() != 0)
        {
            list<matter__c> matter= [Select Id, OwnerId, Client__c, Prospect__c, Billing_RateLU__c from Matter__c where Consultation_Matter__c = TRUE and Set_Inactive__c = FALSE Order By CreatedDate DESC Limit 2];
            
            matter__c previousMatter =matter[1];
            
            if(previousMatter != null)
            {
                Matter__c previousMatterUpdate = new Matter__c();
                previousMatterUpdate.Id = previousMatter.Id;
                previousMatterUpdate.Set_Inactive__c = TRUE;
                Update previousMatterUpdate;
            }
        }
        return null;
    }
}



test class with 36% code coverage :

@istest
public class MonthlyMatterInactiveTest
{
    @istest  
    public static void testMethod2() {
        // code_block    
        // 
        test.startTest();
        Account acct = new Account(
            FirstName='test rohini',
            LastName='test twopir'
        ); 
        insert acct;
        
        Propsect__c prop =new Propsect__c(
            Spouses_First_Name__c='test',
            Spouses_Name__c='test',Person__c=acct.id);
        insert prop;
        

        list<matter__c> matter= new list<matter__c>();
        // matter.add(mat);
        
        Matter__c mattercObj = new Matter__c (
            Client__c = acct.id,  
            Prospect__c = prop.id,
            Status__c = 'Active',
            Type__c = 'Consultation',
            Apply_Fixed_Fee__c = FALSE,
            Fixed_fee_Amount__c = NULL,
            Send_Invoices_By__c = 'Mail',
            Apply_Interest__c = FALSE,
            Set_Inactive__c=False,
            Refresher_Amount__c=2345,
            Refresher_Required__c=true,
            Name='Consultations - Non Retainer ',   
            Consultation_Matter__c=True
        );
        matter.add(mattercObj);
        insert(matter);
        
        MonthlyMatterInactive.monthlyMatterInactive();
        test.stopTest();
    }       
    
}