Skip to main content
New tool CRON Expression Builder — preview next run times before you schedule Apex. Open the builder →
Diagram illustrating the hard limit of 40 lookup fields allowed per standard or custom Salesforce object.
Admin

Salesforce Lookup Limit: 40 Relationship Fields per Object

Each Salesforce object allows 40 custom relationship fields, lookups and master-details combined, with at most 2 master-detail. How to see your real count, and how to redesign before you hit the wall.

The short answer

A Salesforce object can have up to 40 custom relationship fields. Lookups and master-detail fields share that limit, and at most 2 of them can be master-detail. Standard lookups that ship with the object, such as Account on Contact, do not count. Check the real number under Object Manager > your object > Object Limits.

Key takeaways The limit is 40 custom relationship fields per object, shared by lookups and master-details. At most 2 of the 40 can be master-detail. Standard lookups that ship with the object do not count. Object Manager > your object > Object Limits shows usage against Custom Relationship Fields, along with the 5 active lookup filter limit. At 35 or more, redesign: a junction object for many-to-many, one lookup plus a type picklist instead of near-duplicates, or an External ID text field for reference-only links.

A Salesforce object can have 40 custom relationship fields. Lookups and master-detail fields count toward the same 40, and no more than 2 of them can be master-detail. Standard relationship fields that come with the object, such as AccountId on Contact or OwnerId, are not part of the count.

The limit usually turns up mid-build as an error on the field you are trying to create. On a large Service Cloud project I worked on, we hit it on Case because every department wanted its own reference field. Knowing the number early is cheaper than redesigning in the middle of a release.

Where to see your real count

Go to Setup > Object Manager > [your object] > Object Limits. The row you want is Custom Relationship Fields, with its usage and the maximum of 40. The same page shows limits that tend to bite at the same time:

Object limit Default maximum
Custom Relationship Fields (lookup + master-detail) 40
Master-detail relationships 2
Active Lookup Filters 5
Rollup Summary Fields 25
Custom Fields (all types) 500, depending on edition

The relationship, lookup filter, roll-up and custom field figures are what a sandbox reported through the Tooling API's EntityLimit object; the cap of 2 master-detail relationships is a documented platform rule. The Object Limits page in your own org is the number to trust, because edition and installed packages can change what you see.

If you would rather query it, the Tooling API exposes the same data:

SELECT Label, Max, Remaining
FROM EntityLimit
WHERE EntityDefinitionId = 'Case'

Run it with sf data query --use-tooling-api or from the Developer Console with Use Tooling API checked.

Why the limit exists

Every relationship field adds a foreign key that Salesforce has to resolve when records load, enforce in sharing calculations and maintain in indexes. Forty is generous for a well-normalized object. An object with 35 or more relationships is usually doing the job of several objects.

Many lookups pointing at the same small set of parent records also invite data skew, which causes record locking and slow sharing recalculation long before you reach 40.

An interface mockup of a CRM object management screen with a dense list of lookup relationship fields.

What to do when you are near 40

Plan as if the limit cannot be raised, and redesign before the request that would push you over it.

  • Many-to-many relationships. If you have Vendor_1__c, Vendor_2__c and Vendor_3__c, you have a many-to-many relationship. Build a junction object (for example Case_Vendor__c with master-detail fields to Case and Vendor) and remove the numbered lookups. It holds any number of vendors and frees several relationship slots.
  • Near-duplicate lookups. "Primary Vendor" and "Secondary Vendor" can often become one lookup to a partner object plus a Role__c picklist, either on the same object or on a junction record.
  • Reference-only links. If a field only stores an ID from an outside system and nobody navigates to the record, a text field marked External ID may be enough. It does not count as a relationship field.
  • Fields that belong on a child. Department-specific references often belong on a related object that holds that department's data, not on the main record.

Querying across relationships

Each custom relationship gets a relationship name ending in __r, which lets you read parent fields in one query instead of several:

SELECT Id, Name, Account__r.Name, Vendor_Ref__r.Status__c
FROM Custom_Object__c
WHERE Account__r.Industry = 'Manufacturing'

Use __c for the ID value and __r to traverse to the parent. Mixing them up is one of the most common SOQL errors on custom objects.

Summary

  • 40 custom relationship fields per object, lookups and master-details combined.
  • At most 2 master-detail.
  • Standard relationship fields do not count.
  • Check Object Manager > Object Limits for the real usage.
  • Near the limit, fix the data model with junction objects and consolidated lookups rather than hunting for a workaround.
Free tool Schema ERD Viewer Visualize Salesforce object relationships as interactive ERD diagrams. Export as PNG, SVG, or PDF.
Newsletter

One email every Tuesday

New guides, tool updates, and the release-note changes that break things.

No spam. Unsubscribe in one click.

Comments

Loading comments...

Leave a Comment