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
The AdmiralThe Admiral 

Before update trigger, updating a field with formula value.

Hi there,

I have on the object factuur__c a field named FS_Dagen_Open__c it is a formula counting day that the invoice is open. 
The trigger should update Aantal_Dagen_Openstaan on each record on the object.
It also should fire if field Betaald__c is False.

I am quite new to triggers and it seems that i have some issues here, any suggestions for improvements?
 
trigger nota Trigger on Factuur__c (before update) {
    //Create a list to hold the records that we are going to update
    List<Factuur__c> notaList = new List<Factuur__c>();
     Betaald = False
    
    //Go through the updated records in the database and update their custom fields 
    //according to the updated Aantal_dagen_openstaand__c in value of FS_Dagen_Open
    for(Factuur__c nota : Trigger.new)
    {
        if(nota. FS_Dagen_open__c = !=null)
        {
            nota.FS_Dagen_open__c =  Aantal_dagen_openstaand__c;
            
            //Put each updated record in the list we created
            notaList.add(nota);
        }
    }
    //Update the list in the database
    update notaList;

}

 
The AdmiralThe Admiral
Updated it so far to this
trigger nota Trigger on Factuur__c (before update) {
    //Create a list to hold the records that we are going to update
    List<Factuur__c> notaList = new List<Factuur__c>();
     Betaald = False;
    
    //Go through the updated records in the database and update their custom fields 
    //according to the updated Aantal_dagen_openstaand__c in value of FS_Dagen_Open
    for(Factuur__c nota : Trigger.new) {
    
    //Check that FS_Dagen_Open__c is not empty, and also different than the field we have currently
    if(nota.FS_Dagen_open__c !=null && nota.FS_Dagen_open__c != nota.Aantal_dagen_openstaand__c) {
        nota.Aantal_dagen_openstaand__c = nota.FS_Dagen_open__c;
    }
}

I am getting the following error:

 Error: Compile Error: Expecting 'ON' but was: 'Trigger' at line 1 column 14