You need to sign in to do that
Don't have an account?
HARSHIL U PARIKH
Trigger (Small one) works but little trouble with test cases
Hello Developers!
I have a simple trigger which is working fine but I have little trouble in test cases:
Few things to consider:
Master Object: Volunteer_Project__c
Child Object: Participation__c
Trigger:
I have a simple trigger which is working fine but I have little trouble in test cases:
Few things to consider:
Master Object: Volunteer_Project__c
Child Object: Participation__c
Trigger:
Trigger UniqueEmailCount On Volunteer_Project__c(before insert, before update) { List<Participation__c> ParticipationList = new List<Participation__c>(); Set<String> uniqueEmails = new Set<String>(); ParticipationList = [SELECT Volunteer_Email__c FROM Participation__c where Volunteer_Project_Name__c IN :Trigger.New]; for (Integer i = 0; i< ParticipationList.size(); i++) { uniqueEmails.add(ParticipationList[i].Volunteer_Email__c); } for(Volunteer_Project__c proj: Trigger.new) { proj.Total_Associated_Volunteers__c = uniqueEmails.size(); } }Test Cases: (NOT GETTING ANY COVERAGE)
@isTest Public class UniqueEmailCount_Test{ Public Static TestMethod Void TestingUniqueEmailCount(){ Set<String> uniqueEmails = new Set<String>(); List<Participation__c> partiList = new List<Participation__c >(); for(Integer I = 0; I < 200; I++) { Participation__c Parti = New Participation__c (Volunteer_Name__c = 'Person:' + i, Volunteer_Project_Name__c = 'Project:' + i , Devoted_Hours__c = 1); partiList.add(Parti); } insert partiList; for (Integer k = 0; k< partiList.size(); k++) { uniqueEmails.add(partiList[k].Volunteer_Email__c); } List<Volunteer_Project__c> vp = new List<Volunteer_Project__c>(); vp = [Select Total_Associated_Volunteers__c from Volunteer_Project__c]; for (Volunteer_Project__c vp1: vp ){ // system.assetEquls(vp1.Total_Associated_Volunteers__c, uniqueEmails.size()); } } }Note: Volunteer_Email__c is a formula field on child Participation__c. This field is catching emails from contacts.
All Answers
Please try below test class.
Let us know if this will help you
I have added one more thing in trigger. But I was unable to understand how to add those field above. Well, these are all fields for Volunteer_Project__c
Thank you for the followup guys..