• podgercor1.3917890117104897E12
  • NEWBIE
  • 20 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies
I have used some bits of code here to create a Trigger that will count the number of Completed Events on an Account in a certain Fiscal Period - the problem I have is that the code keeps on counting events outside of the quarter - so if I create 2 events - 1 with a due date 28.04.14 and another with 20.02.14 i would expect my code to return only 1 instead it keeps returning 2 - can anyone see what I am doing wrong here?

Trigger

trigger Event_Counter on Event (after insert,after delete,after update,after undelete) {
Set<ID> acctIds = new Set<ID>();
    String prefix =  '001';


datetime myDate = datetime.newInstance (2014, 03,28,00,00,00);
datetime myDate1 = datetime.newInstance (2014, 06,30,00,00,00);

    if (Trigger.new != null) {
        for (Event t : Trigger.new) {
            if (t.WhatId != null && String.valueOf(t.whatId).startsWith(prefix) && t.ActivityDate >= myDate && t.ActivityDate <= myDate1 && t.Meeting_Status__c == 'Completed' && t.Coverage_Report__c == 'Yes' && (t.Meeting_Type__c =='Face to Face Meeting' || t.Meeting_Type__c =='Sales Meeting Call') ) {
                acctIds.add(t.whatId);
            }
        }
    }

    if (Trigger.old != null) {
        for (Event t : Trigger.old) {
            if (t.WhatId != null && String.valueOf(t.whatId).startsWith(prefix)&& t.ActivityDate >= myDate && t.ActivityDate <= myDate1 && t.Meeting_Status__c == 'Completed' && t.Coverage_Report__c == 'Yes' &&( t.Meeting_Type__c =='Face to Face Meeting' || t.Meeting_Type__c =='Sales Meeting Call') ) {
                acctIds.add(t.whatId);
            }
        }
    }

    if (acctIds.size() > 0 )
        Event_Coverage_Count.updateAcctEventCounts(acctIds);
}

Class
public with sharing class Event_Coverage_Count {
    public static Boolean didRun = false;
  
    public static void updateAcctEventCounts(Set<ID> acctIds) {

        if (didRun == false) {
            didRun = true;

            List<Account> acct = [SELECT ID, Completed_Coverage_Count__c, (SELECT ID FROM Events) FROM Account WHERE ID IN :acctIds];
            List<Account> updateAcct = new List<Account>();

            for (Account a : acct) {
                Integer count = a.events.size();

                if (a.Completed_Coverage_Count__c != count) {
                    a.Completed_Coverage_Count__c = count;
                    updateAcct.add(a);
                }
            }
          
            try {
                update updateAcct;
            } catch (Exception e) {
             
            }
        }
    }


thank you
Hi, 

 I am trying to create a trigger that will update a field on the Account based on an Event being marked as complete - the problem i have is that I only want the trigger to fire when the Activity Date is in the Current Fiscal Quarter. I have tried using 
ActivityDate == FISCAL_QUARTER() 
and THIS_FISCAL_QUARTER()
but neither has worked ... any ideas on how I can achieve this ?
thanks
I am trying to deploy a trigger i made but i keep getting an error message that says
"Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required"

from checking other boards I can see that I will have to write a test method for this but how do I do that?

My trigger is as follows
trigger Timestamper on Event (after insert, after update)
{
  List <ID> AccId = New List <ID>();
 
    for (Event e: trigger.new)
    {
     if (e.Meeting_Status__c == 'Completed' && e.WhatId !=null)
         {
          AccId.add(e.WhatId);
         }
    }

 
    List <Account> accList = [SELECT id, Last_Event_Close_Date__c FROM Account WHERE id in:AccId];
    for(Account acnt : accList)
    {
         acnt.Last_Event_Close_Date__c = System.today();
    }
    update accList;
   
   

}

I have tried to start writeg a test class but have no idea where to go with it
@isTest
private class Trig_Test_Timestamper

{
static testMethod void Timestamper() {

        test.startTest();

   
    Event e = new Event (name = 'test');
        insert e;

}

any help would be appreciated
thanks
I'm trying to write a trigger that will fire when an event is marked as Completed (on custom Status field). When this happens I want to update the related Account with a timestamp of when this happened
i.e Event marked completed - Account field Timestamp is set to today

i've tried writing the code for it but have not been able to get beyond the below, any ideas/tips would be appreciated - thanks

code -------------------------

trigger Timestamper on Event (after insert, after update)
{
  List <ID> AccId = New List <ID>();
   
    for (Event e: trigger.new)
    {
     if (e.Meeting_Status__c == 'Completed' && e.WhatId !=null)
         {
          AccId.add(e.WhatId);  
         }
    }

   
    List <Account> accList = [SELECT id, Timestamp__c FROM Account WHERE id in:AccId];
    {
     accList.Timestamp__c = System.today();  
    }
    update accList;
}

i think i am close here but getting an "initial term of field expression must be a concrete SObject" error here??
I am trying to deploy a trigger i made but i keep getting an error message that says
"Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required"

from checking other boards I can see that I will have to write a test method for this but how do I do that?

My trigger is as follows
trigger Timestamper on Event (after insert, after update)
{
  List <ID> AccId = New List <ID>();
 
    for (Event e: trigger.new)
    {
     if (e.Meeting_Status__c == 'Completed' && e.WhatId !=null)
         {
          AccId.add(e.WhatId);
         }
    }

 
    List <Account> accList = [SELECT id, Last_Event_Close_Date__c FROM Account WHERE id in:AccId];
    for(Account acnt : accList)
    {
         acnt.Last_Event_Close_Date__c = System.today();
    }
    update accList;
   
   

}

I have tried to start writeg a test class but have no idea where to go with it
@isTest
private class Trig_Test_Timestamper

{
static testMethod void Timestamper() {

        test.startTest();

   
    Event e = new Event (name = 'test');
        insert e;

}

any help would be appreciated
thanks
I'm trying to write a trigger that will fire when an event is marked as Completed (on custom Status field). When this happens I want to update the related Account with a timestamp of when this happened
i.e Event marked completed - Account field Timestamp is set to today

i've tried writing the code for it but have not been able to get beyond the below, any ideas/tips would be appreciated - thanks

code -------------------------

trigger Timestamper on Event (after insert, after update)
{
  List <ID> AccId = New List <ID>();
   
    for (Event e: trigger.new)
    {
     if (e.Meeting_Status__c == 'Completed' && e.WhatId !=null)
         {
          AccId.add(e.WhatId);  
         }
    }

   
    List <Account> accList = [SELECT id, Timestamp__c FROM Account WHERE id in:AccId];
    {
     accList.Timestamp__c = System.today();  
    }
    update accList;
}

i think i am close here but getting an "initial term of field expression must be a concrete SObject" error here??