You need to sign in to do that
Don't have an account?
S_Batman
Count number of Activities based on date and specific type
I am trying to create a field which would count number of activities starting August 1, 2016. However, I would want it to stop counting once 'Specific' field within Activities is selected as Conversation.
What I am trying to accomplish is having 7 touches (emails, voicemails, dials) one one Account labelled Type = Top X. Once 7 touches and a conversation did NOT take place, I would remove these Accounts from the bucket and place it under different one Type = Nurture.
But before or on the 7th touch, if a conversation did take place (Specific = Conversation), I want to keep them under the Top X Bucket.
Changing the bucket I can do manually, but I do require the counter field.
Is this possible to do with APEX? I have created counter field before, but I have never done something with a date and the counter stopping at a specific time.
Any help is appreciated!
What I am trying to accomplish is having 7 touches (emails, voicemails, dials) one one Account labelled Type = Top X. Once 7 touches and a conversation did NOT take place, I would remove these Accounts from the bucket and place it under different one Type = Nurture.
But before or on the 7th touch, if a conversation did take place (Specific = Conversation), I want to keep them under the Top X Bucket.
Changing the bucket I can do manually, but I do require the counter field.
Is this possible to do with APEX? I have created counter field before, but I have never done something with a date and the counter stopping at a specific time.
Any help is appreciated!
trigger ActivityConversationCount on Activity (after inser, after delete, after undelete, after update) {
set<Id> accIds = new set<Id>();
if(trigger.isinsert || trigger.isUpdate || trigger.ISundelete){
for(Activity con: Trigger.new){
if(Trigger.isInsert || Trigger.isUndelete || (con.Conversation__c !=Trigger.oldMap.get(con.Id).Conversation__c
))
accIds.add(con.AccountId);
}
}
if(trigger.isUpdate || trigger.isDelete) {
for(Contact con: Trigger.old){
if(trigger.isDelete || (con.Conversation__c != Trigger.newMap.get(con.ID).Conversation__c
))
accIds.add(con.AccountId);
}
}
if(!accIds.isEmpty()) {
List<Account> accList = [select id, Number_of_Activities__c, (Select Id, Conversation__c from Contacts) from Account Where ID IN: accIds];
for(Account acc : accList){
system.debug('Activity--->'+acc.activities.size());
acc.Number_of_Activities__c = 0;
for(Contact con : acc.Contacts) {
if(con.Conversation__c)
acc.Number_of_Activities__c++;
}
}
update accList;
}
}
I was trying to have a place where Activities will be counted, but still not sure how to start counting after the due date is August 1/16 and for it to stop when Specific = Conversation..