You need to sign in to do that
Don't have an account?
Sujitha 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;
}
}
}
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;
}
}
}
Then add any system.Asserts to make sure your records are what you want.