+ Start a Discussion
notsosmartnotsosmart 

Cross object display field on Visualforce page

I have a lookup method in my controller extension for a custom object to the Campaign.Type field of Campaign.

my visualforce page references the custom object controller and Extension.

 

How do I reference this field on the page?

 

Excerpts are:

 

Extension -

 

private Trip_Report__c tripReport;
private Campaign campaignInfo;

 

// get display data
if (tripReport.Campaign__c != null) {
campaignInfo = TripRptManager.getCampaign(tripReport.Campaign__c);
}

in The Utility Lib referenced above - 

 

// Display fields

public static Campaign getCampaign(Id campaign){
         
        return [SELECT 
                    Id
                    ,Name
                    ,Type
                  FROM 
                    Campaign
                WHERE
                    Id = :campaign
                ];      
    }

 

 

Page -

 

<apex:page standardController="Trip_Report__c" extensions="TripRptExt" showHeader="false">

 

<apex:outputField value="{!campaignInfo.Type }" /> 

 

The ERROR 

Error: Unknown property 'Trip_Report__cStandardController.campaignInfo'

 

I also tried !relatedTo.Campaign__r.Type  and get the error on 'relatedTo'

 

Any ideas?  Thanks

 

Best Answer chosen by Admin (Salesforce Developers) 
notsosmartnotsosmart
Thanks. That did the trick. Now, if you don,t mind, I have it populating the lookup on initial load of a record but how do I trigger the method that I built in the extension 'getCampaignInfo' when the screen field 'Campaign' is changed?

All Answers

MJR_NexMJR_Nex

 

You have your variable CampaignInfo set to private and it has no getters or setters, so the VF page can't access the variable.

 

Replace this:

private Campaign campaignInfo;

With this:

Public Campaign CampaignInfo{get; set;}

 

notsosmartnotsosmart
Thanks. That did the trick. Now, if you don,t mind, I have it populating the lookup on initial load of a record but how do I trigger the method that I built in the extension 'getCampaignInfo' when the screen field 'Campaign' is changed?
This was selected as the best answer