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
Dosbol TDosbol T 

trigger to auto populate the date based on other date

what is wrong with this code? It says - "Arithmetic expressions must use numeric arguments (4:43)",
  Please help.
trigger AutoPopAccPerDate on Billing__c(before insert, before update) {
  for (Billing__c billing : Trigger.new) {
    if (billing.Accounting_Date__c == null) {
      billing.Accounting_Date__c = Billing__c.Billing_Date__c + 30; 
    }
  }
}

 
Best Answer chosen by Dosbol T
Devid JohnDevid John
Try this:
trigger AutoPopAccPerDate on Billing__c(before insert, before update) {
  for (Billing__c billing : Trigger.new) {
    if (billing.Accounting_Date__c == null) {
      billing.Accounting_Date__c = billing.Billing_Date__c.addDays(30); 
    }
  }
}


The main problem in this line: 

billing.Accounting_Date__c = Billing__c.Billing_Date__c + 30;

You must use billing.Billing_Date__c instead of Billing__c.Billing_Date__c

All Answers

Devid JohnDevid John
Try this:
trigger AutoPopAccPerDate on Billing__c(before insert, before update) {
  for (Billing__c billing : Trigger.new) {
    if (billing.Accounting_Date__c == null) {
      billing.Accounting_Date__c = billing.Billing_Date__c.addDays(30); 
    }
  }
}


The main problem in this line: 

billing.Accounting_Date__c = Billing__c.Billing_Date__c + 30;

You must use billing.Billing_Date__c instead of Billing__c.Billing_Date__c

This was selected as the best answer
Dosbol TDosbol T
@Devid#@000 - Thank you so much, it works!
Dosbol TDosbol T
Why this trigger is not firing when I am updating the record?