
8 个回答
Case 1: If the Relationship is Master-Detail:
Then you can create a custom field with Roll-Up Summary on the Parent object and select the roll-up type as Count.Case 2: If the Relationship is Lookup: Then we have to write the Trigger.Case 3: You can use the subquery or Relationship Query as below:SOQL for two standard objects. Let’s say Account as a parent object and Contact as a child object.
Query to fetch the all Contact which is associated with Account ‘Account1’.// When a record is fetched from ContactSELECT Name, Account.Name FROM Contact where Account.Name = 'Account1'// When a record is fetched from Account.// Contacts is a child relationship name of Contact object.SELECT Name, (SELECT Name FROM Contacts) FROM Account where Name = 'Account1'