Skip to main content
19 votes
Accepted

Set Relationship Via Name Pointing Field?

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 ...
Adrian Larson's user avatar
  • 151k
17 votes
Accepted

Which is faster between static and dynamic getSObjects?

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 ...
Adrian Larson's user avatar
  • 151k
14 votes
Accepted

Accessing the parent sObject from the child sObject?

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 ...
Derek F's user avatar
  • 62.8k
12 votes
Accepted

How to identify look up relations to an object in Salesforce

You could get this with apex describe methods: for ( Schema.ChildRelationship scr : Account.sObjectType.getDescribe().getchildRelationships() ){ system.debug(''); system.debug('**** Child ...
martin's user avatar
  • 12.7k
12 votes

Exact Target: Can someone please tell me the difference between Contact Builder and Data Relationships in Exact Target?

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 ...
Grzegorz Próchnicki's user avatar
12 votes
Accepted

Didn't understand relationship in FROM part of query call

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 ...
Adrian Larson's user avatar
  • 151k
12 votes
Accepted

How to initialize sObject with Relational fields?

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: ...
Adrian Larson's user avatar
  • 151k
11 votes
Accepted

SOQL: Comparing two custom relationship fields in a nested query

Ahh, Salesforce doesn't allow direct field to field comparisons in a query. Source: Field to field comparison in WHERE clause of SOQL Knowledge Article Number 000187460 Description ...
ZAR's user avatar
  • 2,043
9 votes
Accepted

How to use GetSObject to retrieve related data in a null safe manner?

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 ...
Adrian Larson's user avatar
  • 151k
9 votes
Accepted

Can someone confirm if I've identified a bug in Salesforce regarding formula fields?

I believe that this is expected. The reason why is that Salesforce presumes the default value for a field when no object is present. That can make all the difference when you do something like adding ...
sfdcfox's user avatar
  • 497k
8 votes
Accepted

Why can't I see related data in my Apex, or why are related records showing up as `null`?

Everywhere in Apex, it is a fact that you must query relationship data you wish to reference. When you insert a record, the only field in your object that is modified by the Apex runtime is the Id: ...
7 votes
Accepted

Lookup Relationship - traversal level?

Understanding Relationship Query Limitations In each specified relationship, no more than five levels can be specified in a child-to-parent relationship. For example, Contact.Account.Owner....
Ratan Paul's user avatar
  • 22.7k
7 votes

Relationship name between quotes and account

It's a little weird that between Account and Quote there is no ChildRelationship name assigned. On Opportunity Although if you query Quotes you have AccountId to filer by Account while for the ...
Mohith Shrivastava's user avatar
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
  • 151k
7 votes
Accepted

Performance-wise, is it better to query a relationship field or a formula field?

If the formula is literally: Account.Name Then you get the use of indexes, such that: WHERE AccountName__c = 'Demo' WHERE Account.Name = 'Demo' Are identical in performance. If you use any sort ...
sfdcfox's user avatar
  • 497k
7 votes
Accepted

Are the related objects in an SOQL query shared?

Can anyone point me to some documentation that states this as expected behaviour? I've never seen such documentation. Empirically, it appears that the common B__c instances are actually shared (I ...
sfdcfox's user avatar
  • 497k
6 votes

What is the logic for the automatic creation and update of "standard" report types for custom objects?

Based on some light reverse engineering. The "standard" report types are created whenever the enable reports option is checked on a custom object, or a master detail relationship to the reportable ...
Ralph Callaway's user avatar
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,284
6 votes

Which is faster between static and dynamic getSObjects?

I was bothered by null pointer exception when i was experimenting with my code. I changed static access method to getSObjects method and found a strange thing which could be important, when we use ...
patryk's user avatar
  • 655
6 votes
Accepted

SOQL query with inner query doesn't recognize understand the relationship

You missed the s. Notice the describe says the relationship name is cms__Attributes__r, but you have cms__Attribute__r. Invalid (SELECT ... FROM cms__Attribute__r) Valid (SELECT ... FROM ...
Adrian Larson's user avatar
  • 151k
6 votes
Accepted

Lookup field goes on child or parent object?

The related list is always on the parent object, and the lookup or master-detail field is always on the child object. "The child looks up to the parent" might be a useful mnemonic here. In order to ...
sfdcfox's user avatar
  • 497k
6 votes
Accepted

Proper way to make Contract-Order, force 1-1 relationship

Yes, You can do that using standard Salesforce Functionality Create a Field on Order Named as Contract_Unqiue__c and make it as unique field. Create a WF rule on Order and when the order is created , ...
Pranay Jaiswal's user avatar
6 votes
Accepted

Parent to Child SOQL WHERE clause

Assuming the child object name as ChildObjectName__c and lookup API name on child isLookupName__c, your query with where clause would look as: SELECT Id, (SELECT Checkbox__c FROM ...
Raul's user avatar
  • 18.8k
5 votes

How to identify look up relations to an object in Salesforce

There are couple of tools thats very helpful 1.Workbench You can see the Childrelationships to see all the all the objects for which the object is looked upto 2.Appexchange app named Schema Surfer ...
Mohith Shrivastava's user avatar
5 votes
Accepted

Roll-up summary OR workflow

The pros and cons list for rollup summary vs trigger is pretty short. In fact, you've taken care of most of the pros and cons of using a rollup summary in your question. Rollup Summary: Pros: ...
Derek F's user avatar
  • 62.8k
5 votes

Activities on Leads, Opportunities, and Accounts SOQL

The object you should query is OpenActivity and ActivityHistory So your query should be SELECT Report_Country_L__c, (SELECT Owner.Name,ActivityDate,Status,istask,ActivitySubtype, Subject FROM ...
Vigneshwaran G's user avatar
5 votes
Accepted

Question on Salesforce Relationship

The test writers are looking for the Account's relationship to the Warehouse, not the Warehouse's relationship to the Account. That means you have to plug in each word to determine which correctly ...
sfdcfox's user avatar
  • 497k
5 votes

Create relationship between custom object and custom setting

No, you cannot create a relationship from a Standard Object or a Custom Object to a Custom Setting (nor the other way around). As for why, the simple answer is that it is a platform limit. They were ...
Adrian Larson's user avatar
  • 151k
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,108
5 votes
Accepted

Get account by user id

Looking at the User object fields in SFDC ,AccountId and ContactId fields are populated only if your user is a portal/community user Also you can directly use the AccountId field instead of using ...
Mohith Shrivastava's user avatar

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