function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jim MontgomeryJim 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 =[0].Id];   
    String WhoId = t.WhoId;
       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;
       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];
        update a;
Alain CabonAlain Cabon

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:

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];
Hi Could you please try below code and let me know if it works for you.
trigger SoftwareOwnerEventRollupContact on Event (after insert, after update, after delete) {
    if(Trigger.isAfter && Trigger.isInsert){
        Event evntRecord = [select Id,subject, WhoId from Event where Id =[0].Id];   
        if([0].Id!=null || evntRecord != null){
                String WhoId = evntRecord.WhoId;
                    Contact con = [select id, AccountId from contact where id =:WhoId And AccountId != null];
                    Account acc = [select id,software_Owner_meeting_demo__c,Software_Owner__C from Account where Id =:con.AccountId];
                    if(acc.Software_Owner__C != NULL){
                        Id SoftwareOwner = acc.software_Owner__c;
                        user u = [select id, custodial_rep__c from user where ID =:SoftwareOwner]; 
                        Id LoggedUserId;
                        Id CustodialRep;
                        if(u.custodial_rep__c != null)
                            CustodialRep = u.custodial_rep__c;
                            LoggedUserId = u.custodial_rep__c;
                        else  {
                            LoggedUserId = acc.software_owner__c;
                        Integer i = [select count() from Event where WhoId =:con.AccountId and OwnerId =:LoggedUserId and ActivityDate >= 2018-01-01];
                        update acc;

Mark my answer as best if it works for you.

Jim MontgomeryJim Montgomery
Still not updating account when added from a contact.