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

Batch Processing: Formulas


Having read a few posts around formulas in batch processes, it would seem that to get the formula to be accurate you have to include all the formulas accessed fields in the SOQL query.


However, I had done this, and still got some REALLY funky results for my formula.


My formula, which is called "Retrieval Key" is:


TEXT(Country_of_Origin__c) & TEXT(System_of_Origin__c) & Product__c & Product_Category_Lookup__c & IF(MONTH(DATEVALUE(CreatedDate))=1,"January", IF(MONTH(DATEVALUE(CreatedDate))=2,"February", IF(MONTH(DATEVALUE(CreatedDate))=3,"March", IF(MONTH(DATEVALUE(CreatedDate))=4,"April", IF(MONTH(DATEVALUE(CreatedDate))=5,"May", IF(MONTH(DATEVALUE(CreatedDate))=6,"June", IF(MONTH(DATEVALUE(CreatedDate))=7,"July", IF(MONTH(DATEVALUE(CreatedDate))=8,"August", IF(MONTH(DATEVALUE(CreatedDate))=9,"September", IF(MONTH(DATEVALUE(CreatedDate))=10,"October", IF(MONTH(DATEVALUE(CreatedDate))=11,"November", IF(MONTH(DATEVALUE(CreatedDate))=12,"December","")))))))))))) & TEXT(YEAR(DATEVALUE(CreatedDate)))

 and the SOQL statement to retrieve the necessary fields and the Retrieval Key formula field is:



Select t.Retrieval_Key__c, convertCurrency(t.Amount__c), t.Country_of_Origin__c, t.Date__c, t.Points__c, t.Product__c, t.Product_Category_Lookup__c, t.System_of_Origin__c, convertCurrency(t.Turnover__c), t.CreatedDate from Transaction__c t

 The strange behaviour was that the formula would not have the correct System of Origin field, and almost seemed to be swapping system of origins between lines of the retrieved Transaction objects!!


Anyway, any explanation would be appreciated, but also just a heads up to be careful when using batch jobs. This one had my head nearly explode!