We have a Formula Field named My Team on User object which uses the logged in User and Manager Id of the user record to populate YES or NO. This field is used in a report as a filter. So if a Manager logs in and runs this report he will see YES for all the users for whom he is the manager and NO for other. This way a manager can see his Team members on the report by including a filter My Team = YES.

Here is the formula syntax:

IF(Manager.Id = $User.Id ,'Yes', 'No')

The report and the associated Dashboards are taking long time to run due to huge amount data fetched. When we raised the case, one of suggestions from Salesforce was to replace this Formula Field with a Workflow Rule or Trigger. My question is, is it really possible to populate this with WF Rule of Trigger. If yes then can anyone guide me on the how part? The values need to change based on the logged in user.


I think maybe the SFDC agent wasn't quite clear on the problem you're seeing. Yes you could replace the formula with a text field updated by a trigger (and possibly workflow, I can't remember off the top of my head if that can access current user ID) but I'm not convinced that would be much faster than a formula field if at all.

Instead I would suggest following the tips in this cheatsheet: link

Custom indexing could be a good solution to your problem, as per this article:

When you already have a formula field with many dependent SOQL queries and reports, consider using a custom index for the field. As a recent Technical Enablement blog post mentions, you can request salesforce.com Customer Support to create a custom index on a deterministic formula field.

Before requesting an index for a formula field, carefully consider the tradeoffs. Every index you create requires maintenance overhead when DML operations update field values that are referenced by the underlying formula. This overhead can slow the performance of bulk data loads that use the formula field in some way.

| improve this answer | |
  • I agree with @davinC, when you can achieve the functionality using Formula, why to use Apex trigger or WF. On the top of it trigger or WF will execute on when DML is performed. Also if your data is taking longer time to load , it is performance issue of Database not because of Formula. – C0DEPirate Oct 16 '15 at 9:56
  • When you say, Yes the field can be replaced with text field updated by trigger Can you explain how? Trigger will populate value only once based on the event. In my case, the value needs to be changed depending on the logged in user. Secondly, as per the article you shared, my formula field is Non-deterministic, so Indexing is not possible. What is possible is that I incorporate the Formula logic into Report filter itself. – Aryansh04 Oct 16 '15 at 10:12
  • Yes sorry that's what I meant, populate a plain text field with Manager.Username or similar and then filter by that in your report. – Davin Casey Oct 16 '15 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.