We have a community-based application on Salesforce App Exchange. We have a new requirement from one of our clients that they want to use the same application for 2 different departments which are using the same Org.

These departments have different use cases and they must not be able to share data or be able to access each others data (Multi tenant feature ). So we are looking to implement this feature without code change or minimal code change in our product.

We are trying to use record type. According to my understanding, following approach should work.

  • Create record type on the custom object
  • Define its value as "Tenant1", "Tenant2", "Tenant3"...
  • Define a record type default value for different profiles (In our application there are 4 types of users or profiles, and the same page have different data/feature according to profiles).
    i.e. Profile11 -> Tenant1; Profile12 -> Tenant2; Profile13 -> Tenant3;...
  • So when we insert any data in our custom object, then it uses its defined default value and populate it without explicitly defining in code.
  • Query custom object without explicitly defining record type, The APEX query should return only record which is mapped with record type.

Problem which I am facing:

I am able to insert data without changing code using above approach but when I am trying to get data using APEX code then I am getting all data(which are not mapped with user profile. i.e. If I query with Tenant1 profile user then I am getting all data belongs to Tenant1, Tenant2, Tenant3, ....)

So I have two questions:

1st - Does my approach/understanding correct ?

2nd - Can we restrict data query to retrieve only data with defined record type using APEX code without defining in query ?

If my approach is incorrent then please suggest me possible solution.

Edit : My approach to retrive data via Record Type and Profile is not feasible in salesforce Environment. I found one 11 year old unimplemented same feature request on Saleforce site. If other people also like this feature in salesforce then please upvote this feature.

  • What is the Organization-Wide Default for this object? Are there sharing rules in place? Is your Apex running with sharing or without sharing?
    – David Reed
    Mar 27, 2018 at 12:13
  • OWD is private, there is no Sharing rule and we are using "With sharing". Mar 27, 2018 at 12:35

1 Answer 1


Record Types do not control record visibility in SOQL unless the query includes an explicit filter on RecordTypeId, RecordType.DeveloperName, or similar.

However, there seem to be other issues in play. If your query in running in an Apex class declared with sharing and your Organization-Wide Default is Private, then other sharing functionality must be exposing this data. Absent other sharing mechanisms, records owned by other users should not be returned in such a query.

Reviewing the ownership and sharing entries for one of the affected records may help to illuminate whether they are visible to other users due to record ownership or the role hierarchy, a sharing rule, an implicit share, or some other reason.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .