0

I have a 2 fields in Communication__c (Custom object).

field 1: Select_Contact__c (Lookup) (from Contact Object)

field 2: Account_Name__c (Text).

In Visualforce Page,

when ever user selects the contact from lookup , automatically fetch the Related Account name...and displayed in Account_Name__c(Apex:OutputText)

How to achieve this by using SOQL Query.

1

Why not have field 2 be a formula field, then, when you do the lookup, you will get the account name. The formula field would be Select_Contact__r.Account.Name. If you really need it from a SOQL, then the query would be something like:

select Select_Contact__r.Account.name from Communication__c

This of course assumes that the user saved the Communication__c record, so the contact ID is available.

If you need this done more dynamically, you will need an actionfunction on the Inputfield that calls an apex method to re-query the data, and render the section of the VF page where the Account name is posted.

If you could provide more clarity regarding what you are looking to accomplish, and your current code, that would be helpful in correctly addressing your question.

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.