I have two objects - Customer Visit Quota and Contact Report. The contact report object has a "Number of Visits Field" that should roll up on the Customer Visit Quota. I have a master detail look up field on the Contact report object to allow this to happen. My problem is coming in with automatically entering the Customer Visit Quota based on the fields that are already required on the Contact Report. The name of the Customer Visit quota is as follows: External ID Month Year. I have all of those fields on my child object through the account object and a date field. I tried writing a trigger after doing some research - I am really new to coding-, but nothing seems to happen when I create a new Contact Report.
Can someone please help me figure out what I am doing wrong? Let me know if this isn't clear enough and I will try to explain it better.
trigger Quota_Assignment on Contact_Report__c (before insert) {
Set<Id> quotaIdsSet = new Set<Id>();
for(Contact_Report__c conRep:Trigger.New)
{
quotaIdsSet.add(conRep.Customer__r.JDECustomerNumber__c+' '+conRep.Contact_Date__c.month()+' '+conRep.Contact_Date__c.year());
}
Map<Id, String> quotaIdtoQuotaNameMap = new Map<Id, String>();
for(Customer_Visit_Quota__c quota:[Select Id, Name from Customer_Visit_Quota__c where Id in :quotaIdsSet])
{
quotaIdtoQuotaNameMap.put(quota.Id, quota.Name);
}
for(Contact_Report__c conRep:Trigger.New)
{
conRep.Visit_Quota__c = quotaIdtoQuotaNameMap.get(conRep.Customer__r.JDECustomerNumber__c+' '+conRep.Contact_Date__c.month()+' '+conRep.Contact_Date__c.year());
}
}