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
Alex Waddell 12Alex Waddell 12 

Update Account from Custom Object creation - Apex help

Hello everyone,

I am creating a trigger that should update a field on the account page called Fuzion_Billing_Date__c when there are 3 Communication_Note__c records created with the outcome of 'No Answer'

As of right now the code saves but the Fuzion_Billing_Date__c field is not updating when i test. I haven't written a test class yet, I just created three records on a test account to see if it would populate.

Below is my code, I have a feeling the problem lies between lines 10-15, i do not think i am calling for the update properly. Can anyone help me out?
 
trigger billingDate on Account (After insert) {
    For(Account myAcc : Trigger.New){
        List<Account> allAccounts = new List<Account>([Select id,Fuzion_Billing_Date__c
                                                      from account where id in :Trigger.new]);
        List<Communication_Note__c> ThreeUnsuccessful = [Select Id
                                                          From Communication_note__c
                                                          Where Fuzion_Type__c = 'Initial Phone Call'
                                                          AND Outcome__c = 'No Answer'
                                                          And Id = : myAcc.Id];  
        If(ThreeUnsuccessful.size() == 3){
            myAcc.Fuzion_Billing_Date__c = Date.today(); 
        }
		Update myAcc;
    }
    }

 
Alex Waddell 12Alex Waddell 12
Also, I think i have the trigger set up wrong

Shouldn't i be doing "trigger billingDate on Communication_Note__c (After insert) {" rather than on the Account? since i want it to trigger on the third and final Comm note Creation?