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
Deepu161Deepu161 

Can anybody help me to get 100% code coverage for this trigger

trigger PayoffExpenses on Invoice__c (after update) {
    Set<id> invids=new Set<id>();
    for(Invoice__c i:trigger.new){
        if(i.Status__c=='Paid' && trigger.oldmap.get(i.id).status__c!='Paid')
            invids.add(i.Id);
    }
    List<Expense__c> exp=[Select id,Client_Status__c,Invoice__c from Expense__c where 
                         Invoice__c IN : invids and Status__c!='Paid Off'];
    for(Expense__c ep:exp)
        ep.Client_Status__c='Paid';
    update exp;
}
UC InnovationUC Innovation
Hi Deepu,

Great job on the trigger. Real solid. The test class for this is the following. Let me know if there are any issues or if you need some clarification on this. Made some comments and you might need to tweek it a bit for your case.
 
@isTest
private class TestInvoiceTrigger {	
	static testMethod void test	() {
		// Set up test data
		Invoice__c testInvoice = new Invoice__c();
		testInvoice.Status__c = 'Not Paid'; // or something like that
		insert testInvoice;
		
		Expense__c testExpense = new Expense();
		testExpense.Client_Status__c = 'something' // something
		testExpense.Status__c = 'Not Paid Off' // or something like this
		testExpense.Invoice__c  = testInvoice.Id;
		insert testExpense
		
		// actual test code in here
		test.startTest(); 
		{
			testInvoice.Status__c = 'Paid'
			update testInvoice;
		}
		test.stopTest();
	}
}

Hope this helps!

AM