You need to sign in to do that
Don't have an account?
QuickDEV
accessing contact field value from a custom object
Hi all,
I am Facing issues accessing contact.Email field value from a custom object.
Details:
Custom object (obj__C) has a custom lookup field to "Account".
I thought, because Account and contact have a relationship between them, I could use the following.
When I try to use {!obj__c.Account__r.Contact__r.Email} merge field in a VF page, the error is:
Invalid field Contact__r for SObject obj__c.
Any help is greatly appreciated.
Thank you.
Remember that Accounts can have many contacts. You can only traverse object relations "upward". Accessing child object's fields will therefore not work.
You would have to create a lookup the the actual contact you want to reference.
Thanks for your quick reply.
But the problem is, I am trying to pull some fields from Account and contact. If I create the lookup on the custom object for the contact directly, how will I ensure that the fields are pulled from related "Account & contact" objects?
If you only had the contact lookup, you should be able to access the account fields in much the same way you had tried initially. Just "the other way around". Best practice, of course is for every contact to be associated to an account.
E.g: Contact__r.Account.Name
Thank You !
Account & Custom object are related and in use for a while. Lot of custom coding has already been done around that.
Only for the contact.Email field, we need contact.
Not sure if I have to change all the existing stuff just for this. Thinking of trying some workaround in the controller of VF
page.
No Problem. I'm still not sure how you will decide which contact is the one with the right email address, based just on the account, but let us know how it went.