22 votes
Accepted

Cannot set sharingModel to ControlledByParent on a CustomObject without a MasterDetail relationship field

This is a recent issue with Salesforce. To workaround this issue, please add the master detail field (even if it has not been changed) to your deployment and the error will go away. I have already ...
user avatar
  • 1,139
16 votes
Accepted

Obtaining Single Record - SOQL vs. Instantiating New Object

Do not use SOQL unless you must. If all the data you need to update comes from the child, simply use it sans query. Save governor limits wherever possible in your code. Opportunity master = new ...
user avatar
  • 143k
15 votes
Accepted

Is it possible to convert a Master-Detail relationship to a Lookup?

From the Salesforce documentation: Considerations for Relationships Converting Relationships You can convert a master-detail relationship to a lookup relationship as long as no roll-up ...
user avatar
  • 22.3k
14 votes
Accepted

Why can't I create a master-detail relationship between Product and my custom object?

I can't offer you any insight into why you cannot do this, you just can't unfortunately, it's a seemingly arbitrary limitation of the platform and the Product2 object. Unless someone who knows about ...
user avatar
  • 13.3k
12 votes
Accepted

"Cannot set sharingModel to ControlledByParent on a CustomObject without a MasterDetail" on an "sfdx force:source:push"

Based on the workaround from Cannot set sharingModel to ControlledByParent on a CustomObject without a MasterDetail relationship field: Workaround: Add the master-detail lookup field to the ...
user avatar
  • 130k
11 votes

SOQL query to display number of opportunities, number of contacts, from account?

You can approach this in two ways. One, you can perform the parent-child subquery and check the size() of the returned list in Apex: List<Account> accounts = [SELECT Id, Name, (SELECT id FROM ...
user avatar
  • 86.8k
9 votes
Accepted

SOQL Outer Join Multi Level Master Detail Relationship

You are trying to traverse multiple levels in a Parent-to-Child query. From the documentation In each specified relationship, only one level of parent-to-child relationship can be specified in a ...
user avatar
8 votes

Master Detail Relationship

Your only option is changing the Master-Detail relationship to a lookup. In a Master-Detail relationships, according to the documentation: The detail record inherits the sharing and security ...
user avatar
  • 14.5k
8 votes

Is it possible to convert a Master-Detail relationship to a Lookup?

Yes, this is a known issue. Mark Pond is correct, our information in that unit on Trailhead is inaccurate. You can convert as long as there are no RSF fields. https://help.salesforce.com/HTViewHelpDoc?...
user avatar
8 votes
Accepted

Cannot set sharingModel to ReadWrite on a CustomObject with a MasterDetail relationship field

Okay this is how I resolved it. Based on the Metadata Field Types I set the sharingModel and the externalSharingModel both to ControlledByParent and everything built correctly! EDIT When I tried ...
user avatar
  • 4,441
8 votes

The number of Lookup relationship that an object can have are as in today?

By default, the system is limited to 40 lookup fields per object, up to two of which may be master-detail relationships if it is a custom object. You can request more than the 40 relationship per ...
user avatar
  • 433k
7 votes
Accepted

Relationship between Account and Opportunity and Account and Contact

They are a unique category of fields commonly referred to as standard lookup fields. Unlike custom lookup fields, they have the generally have the "cascade deletion" property set to true, ...
user avatar
  • 433k
7 votes

Convert SQL query into SOQL query

Also you can directly query in child object using relationship fields, [select ISOOffice__Merchant_Location__c,Account__r.Name from ISOOffice__Merchant_Opportunity__c where ...
user avatar
  • 3,491
7 votes
Accepted

Any reason not to use Lookups instead of Master-Details for Junction object?

I see two reasons if we use look-up instead of master-detail type relationship: When you delete parent records, its child records will not be deleted. In case you delete both parent records, that ...
user avatar
  • 22.2k
7 votes
Accepted

Roll-up summary implications and behind the scenes calculations

There are following issues in your design. Account data skew: If an Account record has more than 10,000 child records then it is called Account data skew. It can also be broadly called as Parent-...
user avatar
7 votes
Accepted

Illegal assignment from sObject to Id

You should be using the relationship name instead of the object name. Replace below code which is giving the error Revenue_Pipeline__c = new Revenue_Pipeline__c(External_Id__c = ext)); With ...
user avatar
  • 6,303
6 votes

Look Up relation Vs Master detail relation

Primary points in choosing MDR over lookup should be: Does it make sense? Think about structure. What do the objects represent? When you insert a cObj2 does it depends on the related cObj1? Roll-up ...
user avatar
6 votes
Accepted

Do calculations on child records properties for master record

Just create a custom field on the parent object using the rollup summary data type. The field creation wizard will walk you though it. Create a formula field on the child "Total Amount" (quantity * ...
user avatar
  • 433k
6 votes

Can We assign a null value to an Master Detail relationship?

If you would read the description of a Master-Detail field, you would notice the following: Creates a special type of parent-child relationship between this object (the child, or "detail") and ...
user avatar
  • 4,972
6 votes
Accepted

Trigger to prevent edit on parent if there are no related child records

You could also prevent edits by rolling up a count of child records and place a validation rule based on that rollup.
user avatar
  • 10.4k
6 votes

Why can't Leads or Users be Masters in a Master-Detail relationship

This currently is not a functionality in Salesforce. Check out the below excerpt from the Relationships Among Objects developer page. You can define master-detail relationships between custom ...
user avatar
  • 1,017
6 votes
Accepted

Reading and writing child relationships of not-yet persisted SObjects?

You can do it via serialization if you want to go that far: class Proxy { final List<Child__c> records; Proxy(List<Child__c> children) { records = children; } Integer totalSize ...
user avatar
  • 143k
6 votes

Changing Master-Detail to Lookup, who becomes Owner?

The OwnerId value from the Master record is used to set the value of the OwnerId on the child records when the relationship is changed from Master-Detail to a Lookup. Additionally, the Org-Wide ...
user avatar
  • 22.3k
6 votes
Accepted

Does Lookup Skew affect only master-detail relationships or also lookup ones?

Skew and lock contention are generally two different issues. About skew In a nutshell, skew is a matter of probability distribution. A good database index is one that has a uniform-ish distribution. ...
user avatar
  • 48.1k
5 votes

Visibility of records in a junction object - AND based or relationshipOrder based?

If you followed the link from the page you referenced to Custom Object Security Overview you'd have found this: View a record: “Read” permission and read access to the related master record. ...
user avatar
  • 40.4k
5 votes
Accepted

Creating custom object for class roster that would pull a list from contacts

For the above problem, I would suggest creating new Custom object, that will act as a Junction object between Roaster and Contacts. It will have look-up fields to Contact object and Roaster object. ...
user avatar
5 votes

Can Many to Many relationship be achieved using lookup relationship?

Yes you can. A downside is that unlike when you use master-detail relationships, the junction object will not be automatically deleted when one or both of the objects it is relating are deleted. You ...
user avatar
  • 130k
5 votes
Accepted

Inner SOQL child to parent query

For parent field references the extra "select" keyword is not used: List<detail__c> detailObj = [select id, master__r.Id from detail__c]; See the examples in the Using Relationship Queries ...
user avatar
  • 130k
5 votes
Accepted

Unable to query child record through inner query

In setup click go to the child object and then click on the master-detail relationship field to Project and you will see the child-relationship name that should be used in the subquery. Example from ...
user avatar
  • 10.4k
5 votes
Accepted

When using FOR UPDATE does Salesforce also lock the child records in a master-detail relationship?

No. You must independently lock child records that you're interested in. Also see Avoiding Deadlocks, where they mention: Apex has the possibility of deadlocks, as does any other procedural logic ...
user avatar
  • 433k

Only top scored, non community-wiki answers of a minimum length are eligible