Spanning Relationships Limitation
Agh! the dreaded
You have reached the maximum number of 10 object references on XXX.
You must remove at least 1 relationship(s) in order to save this Formula Field.
I HATE this error... probably even more than I HATE the dreaded 5000 Character Limit on Formulas.
So I had to investigate this more fully.
Why it happens
- You have a few formulas a few levels deep, (even referencing other formulas).
- Eg, I created a Formula on the User Object that referenced the User Role, then I wanted to show some details about that User on the Account Record (eg User.CustomFormula__c), so the Relationship on the User formula was to User Role, but on the Account it was to User then User Role.
Examples
- People want to do Emails, and don't want to use Visualforce Email Templates, so try to bring all the values they need to reference, onto the object they are sending the email from. Just use Visualforce Emails!
- People want to see all related information on the same page - eg, you have an Account, and on the Contract you want to see the Account Email, the Account Primary Contact's Phone Number etc. Nope! Just use Hover Pages.
- A complex web of lookups. Try using Workflows or Rollup Helper instead.
Options
- Audit - WHY are these fields in use? Are they being used?
- Increase the limit to 15 with a Salesforce Support ticket.
- Simplify your process.
- Workfows, Process Builder, Flows or at last resort Triggers to update the fields.
- Use Visualforce Email Templates
- Make a Visualforce page showing the fields for the related object and show that on the page layout under the lookup field (interestingly, Microsoft Dynamics CRM 2013+ does this very very nicely).
Notes
Official KB Article https://help.salesforce.com/HTViewSolution?id=000006372&language=en_US
- The limit of spanning relationships only includes references made to different objects.
One response:
- Consider if there are other ways to expose data in formula fields. For example if you want to see information on an object 1-2 levels away on an object’s detail page but not report on it, you can require users to hover over the lookup link to view the details.
- If you have multiple references to the same type of object (for example, you reference four different contacts in formula fields, each with a different purpose), consider creating a junction object so you can display the referenced objects in a related list.
- If you have references that are only used in validation rules, rewrite those rules as an Apex trigger.
- If any of the references are used by only one component, convert that to a trigger.
- If you are spanning multiple levels of a hierarchy such as parent accounts, cases, or a hierarchy of custom objects, see if it’s possible to flatten the hierarchy.
https://success.salesforce.com/ideaView?id=08730000000hDO6AAM
Another product manager response that is good https://success.salesforce.com/ideaView?id=08730000000gKsbAAE
Be Aware! Appexchange Apps will also use up your limits! https://success.salesforce.com/answers?id=90630000000goLqAAI