3

I think my question title says all, but still let me explain. When I was (SOQL) querying on Account object, I came across Account.Name which has dot (.) and AccountId without dot(.)notation. I was trying to give it a logic behind it. My logic: when account object was created, system(or Database) would auto generate the id for each record/object, so it wouldn't need Id. Hence we can directly call it as AccountID. Well the question is, system also generates CreatedBy. In that case, I should be able to use AccountCreatedBy, Which clearly didn't work for me.

I'm so in love with this community. Thanks A Ton.

10

When you do a SOQL always the relationships are denoted by __r for custom objects while for standard objects its object Name usually.

If you are moving from Child to Parent or from parent to child in soql then field relationship Name comes into picture.

Now lets say we have query on contact as below,

[Select Id,AccountId,Account.Name from Contact]

Here AccountId is direct lookup field from contact to Account while to extract more information from related Account we go for Child relationship notation like Account.Name ,Account.CreatedBy

Another way to obtain AccountId will be as below

[Select Account.Id ,Account.Name from Contact]

Here we go from reference field Account to get its ID instead of using direct field.

Using Developer console and eclipse for queries will help you understand more . InShort AccountID is direct field referenced while Account.Name is how we traverse relationship

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.