We have two objects "Project" and "Project Members". Project is child of some other object with master-child relationship. So, we can't have "Master-Detail" relationship between "Project" and "Project Member" object and we are using "Lookup Relationship".

There is a requirement on "Project" object to show diffrent details of "Project Member" who has role called "Project Manager". So, we have added a hidden lookup of "Project Member" on "Project" object. Which we are setting by trigger when a "Project Member" record is created with role called "Project Manager". Also, there are some cross object formula on "Project" which takes details of "Project Manager" records.

enter image description here

With this implementation, functionality is working fine. But, it is a circular reference of lookups between "Project Member" and "Project". By this hidden lookup, One "Project" can have one or more "Project Members" in "Project Member" related list. But "Project" will have always one "Project Manager" value in "Project Manager" lookup.

Let me know, if it is ok to use circular lookup reference in such scenario? Because it gives us below advantage :

  • Not any affect on reports
  • With cross-object fomula, we can populate more detail of "Project Manager" in future. (Less Code needed)
  • No need of trigger to populate "Project Manager" details on "Project" record.
  • Not that you can't get good advice here, but yours is a pretty common use case. Do you have a specific question? Are you running into any problems with it?
    – Adrian Larson
    Feb 9 '16 at 6:47
  • Thanks @AdrianLarson for your feedback. My question is "Is it ok to use circular reference in such scenario"? As of now, we are not facing any technical issue with this. If it is an common use case and people are using lookup relationship in the way mentioned above, it answers my question.
    – Ashish
    Feb 9 '16 at 6:54

Salesforce won't have any issue supporting this architecture. It is fairly common to have a child record with special significance, especially with team member setups. You could create a circular reference, but you would be unlikely to do so on accident. For example, the following would break if you went past ten lookups.

Project__c project = new Project__c();
  • I thought it was five lookups. Is this a recent change?
    – sfdcfox
    Feb 9 '16 at 7:08
  • @sfdcfox Hmm I always thought it was 10. Here is one link supporting that number. I'm not sure when if ever it changed, it was the only number I ever heard. It does mention formulas specifically though, so I'm not sure if it applies to Apex.
    – Adrian Larson
    Feb 9 '16 at 7:09
  • Formulas have more power than queries, for sure. SOQL still seems to be limited to five relationships in a hierarchy, although Apex Code can run through much more deeply nested objects than that.
    – sfdcfox
    Feb 9 '16 at 7:19
  • @sfdcfox Interesting, I'll keep that in mind as it is relevant to some current development. Right now we're going up to five levels deep in SOQL...hopefully we don't find the need to go any further.
    – Adrian Larson
    Feb 9 '16 at 7:22

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.