function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AlbertoSMAlbertoSM 

Get a value of a Master Detail relationship through query

Hi everyone,

Two custom objects. They are related as Master Detail:
Store__c and Postal_Code__c. 

I have a visualforce that, depending of the Postal_Code__c you introduce, shows the store that corresponds to that postal code.

Can anyone tell me how to write the function in the controller and the corresponding query?

Thanks a lot for your time!
Cheers
Alberto

 
v varaprasadv varaprasad
Hi ,

please try like below code : 
public string accname{get;set;}

public void getAccountname(){
contact con = [select id,lastname,account.name from contact where MailingPostalCode ='66045'];
string accname = con.account.name;
system.debug('==accname=='+accname);
}

Hope This helps.
Please let me know incase of any further assistance.

Thanks
Varaprasad
 
Ahmad J. KoubeissyAhmad J. Koubeissy
you dont need a query to do that, just reference the lookup field in the visualforce page input field:

<apex:InputField value="{!Postal_Code__c.store__c}">

Please mark as best answer if this solves your problem.