You need to sign in to do that
Don't have an account?
Jim Montgomery
trigger on task not updating account when initiated from contact record
Here is my trigger code. Should count the number of events associated to the account the contact belongs to.
It is not updating the account.
trigger SoftwareOwnerEventRollupContact on Event (after insert, after update, after delete) {
if(Trigger.isAfter && Trigger.isInsert){
Event T = [select Id,subject, WhoId from event where Id = :trigger.new[0].Id];
if(trigger.new[0].Id!=null){
if(T.whoID!=null){
String WhoId = t.WhoId;
if(Whoid.startswith('003')){
Contact C = [select id, accountid from contact where id = :WhoId];
Account a = [select id,software_Owner_meeting_demo__c,Software_Owner__C from Account where id =:C.AccountId];
Id SoftwareOwner = a.software_Owner__c;
if(softwareOwner != NULL){
user u = [select id, custodial_rep__c from user where ID =:SoftwareOwner];
Id LoggedUserId;
Id CustodialRep = u.custodial_rep__c;
if(custodialRep!=null){
LoggedUserId = u.custodial_rep__c;
}
else {
LoggedUserId = a.software_owner__c;
}
Integer i = [select count() from Event where AccountId = :C.AccountId and OwnerId = :LoggedUserId and ActivityDate >= 2018-01-01];
a.Software_Owner_meeting_demo__c=i;
update a;
}
}
}
}
}
}
It is not updating the account.
trigger SoftwareOwnerEventRollupContact on Event (after insert, after update, after delete) {
if(Trigger.isAfter && Trigger.isInsert){
Event T = [select Id,subject, WhoId from event where Id = :trigger.new[0].Id];
if(trigger.new[0].Id!=null){
if(T.whoID!=null){
String WhoId = t.WhoId;
if(Whoid.startswith('003')){
Contact C = [select id, accountid from contact where id = :WhoId];
Account a = [select id,software_Owner_meeting_demo__c,Software_Owner__C from Account where id =:C.AccountId];
Id SoftwareOwner = a.software_Owner__c;
if(softwareOwner != NULL){
user u = [select id, custodial_rep__c from user where ID =:SoftwareOwner];
Id LoggedUserId;
Id CustodialRep = u.custodial_rep__c;
if(custodialRep!=null){
LoggedUserId = u.custodial_rep__c;
}
else {
LoggedUserId = a.software_owner__c;
}
Integer i = [select count() from Event where AccountId = :C.AccountId and OwnerId = :LoggedUserId and ActivityDate >= 2018-01-01];
a.Software_Owner_meeting_demo__c=i;
update a;
}
}
}
}
}
}
Integer i = [select count() from Event where AccountId = :C.AccountId and OwnerId = :LoggedUserId and ActivityDate >= 2018-01-01];
Calculation of the Account ID of an activity: https://help.salesforce.com/articleView?id=000194177&type=1
Are you sure of the query above otherwise you can try:
Integer i = [select count() from Event where WhatId = :C.AccountId and OwnerId = :LoggedUserId and ActivityDate >= 2018-01-01];
Mark my answer as best if it works for you.
Thanks,
Rahul