Search code examples
salesforceapex-code

salesforce.com Formula : How to check if the Record is new


I have to calculate the agreement value for my new record .Assuming that agreement value is ending_days - begining_days. I have put this formula in my object.

IF(Beginning_c <> Ending_c,Ending_c-Beginning_c,0).

I have two questions related to this

1: What is the agreement value ?, Am i correct in assuming what i have assumed or does it some specific other meaning?

2: I have to create an agreement value for new records only. So, should i take care of this fact in my IF condition For example : should my IF code look something like this

IF (AND(//somehow check if the record is new,Beginning_c <> Ending_c),Ending_c-Beginning_c,0)


Solution

  • First, if Beginning__c == Ending__c then Ending__c-Beginning__c is already 0 so your formula does not need IF at all.

    Second, formula is evaluated every time its referenced in SOQL, if you want a once-off calculation you should use before insert trigger or a workflow and store result in regular field.