+ Start a Discussion

How to get contact associated account filed value

Hi All,

I have Account object and Issue(custom object). Issue object have look up relation with Account. I have a button called create Issue on Account object which is overriden by VF page. When I click on create Issue, i want to render some fields based on associated account region. so in my controller i want to check something like below.
If(Issue__c.Account__r.Region__c == 'abc') is this the correct way? I am getting the expected value. Can some one please help me with this pls?

Hi Chubby,

Please find below code for your reference:-

Issue__c issueObj = [select id,Name,Account__r.Region__c from Issue__c limit 1];
if(issueObj != null){
    if(issueObj.Account__r.Region__c == 'North'){
        //display your field as per your requirement
        system.debug('Is North Location- '+ True);
        system.debug('Is North Location- '+ False);

User-added image

Let me know in case of any concerns.

Please mark this answer as the solution/ best answer if it solves your purpose so that it can help other community members.

Pramod Nishane
Salesforce Consultant
Varasi LLC
Prashant Pandey07Prashant Pandey07
Hi Chubby,

I would recommend rendering within the visualforce page..the code will be something like this..
<apex:inputField value="{!issue.some_issuefield__c}" rendered="{!IF(acc.Region__c == 'abc')}"/>

Let me know if you need the full code.