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
Sujitha VedagiriSujitha Vedagiri 

Can anyone help me in writting test class for below code

trigger maxVisitDate on Meeting_Plan__c(after insert, after update, after delete) {
    Set<Id> accIds = new Set<Id>();
    List<Account> listAccUpdate;

    if (!Trigger.isDelete) {
        for( Meeting_Plan__c newMeet : Trigger.new) {
            accIds.add(newMeet.Meeting_Plan_Related_to_Account__c);
        }
    }

    if (!Trigger.isInsert) {
        for (Meeting_Plan__c OldMeet : Trigger.oldMap.values()) {
            accIds.add(OldMeet.Meeting_Plan_Related_to_Account__c);
        }
    }

    accIds.remove(null);

    if (!accIds.isEmpty()) {
        listAccUpdate = new List<Account>();

        for (AggregateResult ar : [
            select MAX(Visit_Date__c) date,
                Meeting_Plan_Related_to_Account__c
            from  Meeting_Plan__c
            where Meeting_Plan_Related_to_Account__c in :accIds
            group by Meeting_Plan_Related_to_Account__c
        ]) {
            //vendorProductsToUpdate.add(new Vendor_Product__c(Id = ar.Vendor_Product__c,Current_MRR__c = ar.get('expr0')));
             Account acc=new Account();
                 acc.Id=(ID)ar.get('Meeting_Plan_Related_to_Account__c');
                acc.Last_Customer_Visit_RollUp__c=(Date)ar.get(String.valueOf('date'));
                
                 // acc.Last_Cust_Visit_Rollup_Helper__c=(Date)ar.get('Visit_Date__c') ar.get('date');;
                 listAccUpdate.add(acc);

        }

        if (!listAccUpdate.isEmpty()) {
            update listAccUpdate;
        }
    }
}
Brian Cherry 11Brian Cherry 11
Create a test class that inserts a Meeting_Plan_c, updates it, and deletes it. That should give you 100% test coverage.
 
@isTest
public class testMaxVisitTrigger {

    public static testMethod void createMax()
    {
Account acct = new account(Name='Test Account');
insert acct;

Meeting_Plan__c meeting  = new Meeting_Plan__c (Meeting_Plan_Related_To_Account__c = acct.id, Visit_date__c = system.today(););
insert meeting;
update meeting;
delete meeting;
}

}

Then add any system.Asserts to make sure your records are what you want.