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 ...
Adrian Larson's user avatar
  • 150k
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 ...
Keith C's user avatar
  • 136k
12 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 ...
David Reed's user avatar
  • 92.6k
10 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 ...
Arthlete's user avatar
  • 4,907
10 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 ...
Vijay Ganji's user avatar
  • 6,586
9 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-...
Santanu Boral's user avatar
9 votes

What is the maximum number of lookup relationships an object can have?

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 ...
sfdcfox's user avatar
  • 487k
8 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. ...
Derek F's user avatar
  • 60.9k
7 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 ...
cmmoutes13's user avatar
  • 1,037
7 votes

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 ...
Adrian Larson's user avatar
  • 150k
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 ...
Novarg's user avatar
  • 5,256
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 * ...
sfdcfox's user avatar
  • 487k
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.
Jenny B's user avatar
  • 10.5k
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 ...
Mark Pond's user avatar
  • 22.9k
5 votes
Accepted

Unable to create Master Detail Relationship

As per Salesforce documented here: You cannot create a master detail relationship with a object which is a junction object. Please find the screenshot below: Custom junction objects can't have ...
Shailesh Patil's user avatar
5 votes
Accepted

profile object permissions for a detail record

This refers to objects which are related by the master detail relationship. In case of such relationships we have two objects - parent ( usually referred as Master) and child(referred as detail). When ...
Shailesh Deshpande's user avatar
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 ...
sfdcfox's user avatar
  • 487k
5 votes
Accepted

Can a master-detail relationship be blank?

Master-Detail fields are a special kind of required fields, it has special considerations beyond just whether a value is required or not. When you set up a child as a master-detail, you're saying that ...
RCS's user avatar
  • 2,110
5 votes

Deleting Custom Objects

When you go to the "Custom Fields & Relationships" section of the custom object definition, there will be a bold link labeled "Deleted Fields (#)". If you click on that link, it will take you to a ...
martin's user avatar
  • 12.6k
5 votes

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

If you are talking about total no. of Opportunity associated with all the accounts in your org:- SELECT COUNT(Id), Count(Accountid) From Opportunity the following query returns the number of ...
sanket kumar's user avatar
  • 15.2k
5 votes
Accepted

Master-Detail relationship questions

Record Sharing and CRUD/FLS access are very different things. You are correct that the detail will inherit the sharing from the master. CRUD and FLS are controlled by Profiles and Permission Sets. See ...
Bob Lopez's user avatar
  • 1,471
5 votes
Accepted

Count the number of details in master-detail relationship

use count aggregate function. You can have Set<Id> masterIds = ... in this case you can use in SOQL operator. List<AggregateResult> result = [ select count(Id)cnt, Master_Type__c ...
Oleksandr Berehovskyi's user avatar
4 votes
Accepted

Can I get roll-up summary field without a master-detail relationship

Yes, quite simply, you should install declarative-lookup-rollup-summaries. Then you can create a Lookup Rollup Summary to implement this functionality.
Adrian Larson's user avatar
  • 150k
4 votes
Accepted

How to get 'Roll up summary field' in "Master Detail Relationship" on 'Detail page' using Formula?

I just created a formula field on a child object which takes value from Roll-up summary field of Parent. So yes it is possible. My Rollup summary and formula fields are of following type: Rollup ...
Mr.Frodo's user avatar
  • 5,804
4 votes
Accepted

Unique records in related many to many sObjects

Duplicate Management This could be performed using Duplicate Management features of the platform. You would set up a Matching Rule on the TerrWorker object which would reference the combination of ...
Mark Pond's user avatar
  • 22.9k
4 votes
Accepted

roll up summary field on account related to opportunity

This feature was delivered in Spring 08 based on this Idea: Roll-up Summary Fields for Account - Opportunity Standard Relationship The recently announced Winter 08 feature - Roll-up Summary Fields ...
Adrian Larson's user avatar
  • 150k
4 votes
Accepted

Best Relationship to choose in the scenario

It's Lookup relationship since it's mentioned clearly as distinct record owner. In master detail, master objects only have owner. So Answer is B.
Robert Thomas's user avatar
4 votes
Accepted

How to handle Roll Up Summary type Calculations WITHOUT using Master-Detail

The standard go-to answer is to use Andrew Fawcett's excellent Declarative Rollup Summary package. There's a managed package install link, and it comes complete with a UI for configuring your desired ...
sfdcfox's user avatar
  • 487k
4 votes
Accepted

100.000 children in Master Detail relationship? What's the downside?

A few issues Deleting, updating rows, record locking Deleting: You can not delete more than 100k rows In a single Apex transaction, but wait it gets worse. This includes child rows that have been ...
Luke Cotter's user avatar
4 votes

Master-detail relationship between standard objects

There are indeed Master Detail relationship between Standard object. Opportunity and Opportunity product (Opportunity Line Item) are one example of this. But you can't create a new MD between ...
Tushar Sharma's user avatar

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