You need to sign in to do that
Don't have an account?
apex map question
I've got a map in a trigger on a custom object. Custom object is called Customer_Usage__c, and Account__c is a lookup field on that object to the standard Account object.
AccountMap.put((ID)q.get('Account__c')
so that is putting in the ID of the account record to which that customer usage record belongs
Can I access a related record on the Account object here? In other words I want something like
AccountMap.put((ID)q.get('Account__r.Referring_Partner__c')
where Referring_Partner__c is a a lookup field on the account object itself. So I'd be putting in the ID of the value in the referring partner on the account to which the customer usage record belongs.
Trigger saves but throws an error in testing saying the field does not exist. Is this syntax error or am I doing something dumb?
Hi,
You can't reference the field in trigger like "Account__r.Referring_Partner__c" even this is a lookup field. Reason behind it is only id is populating in lookup field not entire account object so you have to query this object if you want to update any field of account object. i am giving a code snippet for that.
[If you got answer from my post please mark it as solution.]
Thanks,
Kapil
Yeah nothing seems to be working but thanks. Maybe you can look at my code and tell me what is wrong.
This trigger works but not the way I want it to. The trigger below updates a field on the account record to which the customer usage record belongs. What I want it to do is exactly what it does now, but, I want it to update the field on an account that is related to the account called Account.Referring_Partner__c
The field Referring_Partner__c is just a lookup field on the account object to the account object itself.
So at the very end there, I want it to be something like
a.Referring_Partner__r.Partner_First_Gross_Add__c, instead of a.Partner_First_Gross_Add__c
I'm thinking I need to add another set or list to this trigger to do that but can't seem to get it to work. The code compiles everytime I adjust it, but when I test I run into errors.
Any ideas guys?
for(Customer_Usage__c q : [select Id,First_Positive_Invoice_Date__c
from Customer_Usage__c where Account__r.Referring_Partner__c IN :AccountIds ,...
is wrong,
you should get the value of 'Referring_Partner__c' from the 1st query, and update it in the second query.
for(Customer_Usage__c q : [select Id, Account__r.Referring_Partner__c, First_Positive_Invoice_Date__c
from Customer_Usage__c where Account__c IN :AccountIds,....
(ID)q.get('Account__r.Referring_Partner__c'),
(Datetime)q.get('First_Positive_Invoice_Date__c')
then find the Account of 'Account__r.Referring_Partner__c' and update the field,...