26

Create a text field (External Id, Unique) on the junction object. Create a workflow on C to fire Everytime the record is created or edited (to account for cases where junction object records are reparented) to set this field as the concatenation of the Ids of A and B records that the C record is relating. This workflow trying to set the composite primary ...


20

Data Model and Terminology Given an object Parent__c and object Child__c with a lookup to Parent__c. Field Name API Name for the lookup field on Child__c, i.e. Child__c.Parent_Lookup__c Parent Relationship Name Use to reference fields on the parent from the child object, i.e. String parentName = child.Parent_Lookup__r.Name. Derived from field name. Child ...


19

__r represents a custom relationship. There are two uses for __r. We use it when we query a custom relationship from child to parent, or from parent to child. For example, if you have two custom objects, called Service__c and Service_Line__c, where the Service Line has a field that references a Service as its parent, you can query from child to parent, or ...


18

There are four different kind of relationships in the force.com platform. But I like to categorize them in a slightly different way than the help pages: Lookup Master-Detail Hierarchy Standard relationships There are lot's of help topics and articles on Lookup and Master-Detail, such as the relationship overview and the relationship considerations ...


16

You need to add all fields that you want access to to your SOQL query, this includes relationship fields. Even if you query for Agreement_CSH_to_be_completed_by__c You need to add the fields that you want to access in your query such as Agreement_CSH_to_be_completed_by__r.isActive If you update your SOQL, this should work fine EDIT in response to ...


16

First, I highly recommend you read Bob's post for yourself. He's a much better writer than I am. Also, Salesforce documents this behavior in Relating Records by Using an External ID and Creating Parent and Child Records in a Single Statement Using Foreign Keys. To relate a record to its parent record with an external ID, the parent object must have a custom ...


15

Functionally, there is no difference. These two options return the same data. These functions are mostly the same. From a performance perspective, the static approach is approximately 2.5x faster. I ran 25 trials each of 1,000 calls, and the static approach averaged 20.48 ms (20.48 µs per call), whereas the dynamic approach averaged 51.40 ms (51.40 µs per ...


14

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 summary fields exist on the master object. You can convert a lookup relationship to a master-detail relationship, but only if the lookup field in all records ...


14

You should use the getRelationshipOrder() method available in the DescribeFieldResult class. This is populated only for Master-Detail relationships and is null for lookup relationships. RelationShipOrder : The type of relationship for a master-detail relationship field. Valid values are: 0 if the field is the primary relationship 1 if the ...


13

You can use a subquery to filter out Parent Records that don't have a related child, eg Select Id, Name from Account where Id In (Select AccountId from Contact) In your case Select Id, Name from Parent__c where Id In (Select ParentId__c from Child__c)


12

When using aggregate functions like count, all other fields must be grouped. Try select problem__r.name,problem__r.status__c,count(casenumber) from case where problem__c!=null group by problem__r.name, problem__r.status limit 10


12

Unfortunately this is not possible in a single query. You are trying to traverse multiple levels when moving from Parent-Child. You can only traverse one level when dealing with Parent to Child. When dealing with Child to Parent, you can traverse up to 5 levels. From the Documentation In each specified relationship, no more than five levels can be ...


11

I don't think there is a child relationship SocialPersonas available. Follow these steps, to see the ones available Log in to the Developer Workbench jump to "Standard & Custom Objects" Choose the object "Case" Open the "Child Relationships" folder To find the API name you need to use in your SOQL query: Open the child relationship you want See the ...


11

You could get this with apex describe methods: for ( Schema.ChildRelationship scr : Account.sObjectType.getDescribe().getchildRelationships() ){ system.debug(''); system.debug('**** Child SObject **** ' + scr.getChildSObject()); system.debug(' Field **** ' + scr.getField()); system.debug(' Relationship Name ...


11

Contact Builder (more exactly Data Designer) basically is doing the same thing as Data Relationships, but those connections are used in different places. From the GUI perspective, Data Designer was created many years after Data Relationships, so building relationships in that module is a bit more convenient and look and feel of available controls is more ...


11

The only way to get data is to either query for it, or create it. That's just the way it is. The other answers (so far) have gone into how you can write a query to get at the data you're seeking, but I'd like to dive deeper into answering your question about why your experiment returned null values. Things you need to know to understand why your experiment ...


11

You need to use the name pointing reference: MyObject__c record = new MyObject__c(); record.Parent__r = new Parent__c(Name='Populated'); The above is functionally equivalent to putSObject: MyObject__c record = new MyObject__c(); record.putSObject('Parent__r', new Parent__c(Name='Populated')); You can also use name=value pairs in the constructor for CPU ...


10

The relationship fields on Activity aren't actually Lookups, but polymorphic relationship fields. This is a special field type that the platform uses when a child record can have a relationship to more than one type of Parent. They aren't available as a field type to Salesforce users when defining new relationships in the database but they do show up on a ...


10

I am assuming this is in reference to your previous question about relationships Parent and Parent.Id with custom objects The relationship names to be unique for that object. So say you have a custom object cus__c and lookup field to an Account. To access the Account fields from the cus__c record you would use cus__c.Account__r.FieldName If you added ...


10

Contacts and Accounts have a lookup relationship but this relationship has a property called CascadeDelete set to true. This is why the contact is deleted when the parent object is deleted. .


10

UI If you would like to enable creation of both of these records at the same time, you will need to create a Flow or a VisualForce wizard. I have more experience with the latter, but believe the former is more configurable and overall lower effort. Validation EDIT As noted by SFDCFox, you will need to have a clause that checks NOT(ISNEW()), because the ...


10

The syntax for a child relationship is: [namespace__]relationship_name__r So if the relationship_name is Impacted_Products and the namespace is MC, your sub-query would be: (SELECT Id FROM MC__Impacted_Products__r) It looks like you used [namespace.] instead of [namespace__]. Note that you can always run this script to get the verbatim value you need to ...


9

Both points are correct, see here ERD: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_erd_products.htm


9

You need to add a null check. The only reason this would fail is if your parent record is null. One option may be to just get the value statically: String text = record.Parent__r.TextField__c; If you cannot use a static reference, I recommend a cross object getter like I shared here. First create this top-level class: public with sharing class CrossObject ...


8

There are a number of considerations when building out many to many relationship in Salesforce: Querying the objects in your code Look and feel of the linked objects. Security and sharing settings of the objects involved in the relationship. The reason Salesforce recommends building a many-to-many relationship can be found in this section of the ...


8

__c is for Custom objects For example: Custom_Object__c . It is used for reference custom object in Apex or visualforce page, formula field etc internally. Used as suffix. __r is for Custom objects reference For example: Custom_Object__r . It is used for reference custom object relation ship name in Apex or visualforce page, formula field etc. Used as ...


8

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 query. For example, if the FROM clause specified Account, the SELECT clause could only specify the Contact or other objects at that level. It could not specify a ...


8

You can't force record creation of the Address__c record on insert of the Account, because there will never be a child record when the record is created (the parent must exist before the child can be linked to it). You can prevent any further edits on the account record after creation by using a validation rule and a roll up summary field, as noted in the ...


8

Triggers can fire on ContentVersion when new ContentDocuments are created or updated. See my answer to Trigger on ContentDocument not working for more on this. It appears to me, based on what I've italicized below, that you need to be querying by getting the ContentDocumentId from the ContentVersion Object instead of the ContentDocument Object, especially ...


8

Once upon a time, the Child Relationship Name was an optional field. If you didn't put a value in, Salesforce chose a default value for you (I'm pretty sure it's the field's ID preceded by an R). Eventually they made this value mandatory, and is also required when using migration tools (e.g. tested in the Force.com IDE).


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