Can someone please explain how to reference fields from parent thru custom lookup?
To clarify, I created the example below, where the compiler hates line 7 (but there is no issue on line 3).
Line: 7, Column: 11 Variable does not exist: Account
1 for (Contact c : [SELECT Id from Contact WHERE CreatedDate = TODAY]){
2 if (c.Account.Count__c != null)
3 c.Account.Count__c = 50;
4 }
5
6 for (Employee__c e : [SELECT Id from Employee__c WHERE CreatedDate = TODAY]){
7 if (e.Account.Count__c != null)
8 e.Account.Count__c = 100;
9 }
When I change line 7 to the lookup name 'Account__c', the compiler also hates that:
7 if (e.Account__c.Count__c != null)
Line: 7, Column: 11 A non foreign key field cannot be referenced in a path expression: Account__c
Question 1: Why on Contact there is possibility to use "Account" reference? The lookup to Account is named "AccountId", so I don't get it. Is it because there is some standard relationship or a different reason?
Question 2: How to work with such scenarios on objects with custom lookups/objects?
Question 3: If there is more to it, can you please refer me to some articles?