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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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?...
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 ...
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 ...
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, ...
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
...
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 ...
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-...
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
...
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 ...
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 * ...
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 ...
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.
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 ...
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 ...
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 ...
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. ...
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. ...
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.
...
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 ...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
master-detail × 389apex × 96
lookup × 67
trigger × 50
relationships × 40
custom-object × 38
soql × 33
roll-up-summary × 28
visualforce × 26
custom-field × 14
junction-object × 14
sharing × 13
related-list × 13
externalid × 12
query × 10
formula × 10
reporting × 8
opportunity × 7
visual-workflow × 6
process-builder × 6
formula-field × 6
custom-button × 6
account × 6
salesforce-id × 6
delete × 6