public class TrackerExt {
    public String OpportunityId {get;set;}
    private final Opportunity opp;
    public List<Tracker__c> trackers{get; set;}

    public TrackerExt(ApexPages.StandardController controller) {
           this.opp = (Opportunity)controller.getRecord();
    public List<Tracker__c> fetchTracker(){
        trackers= [Select Name, Createddate, Object__c from Tracker__c where opportunity__c=:opp.id];
        return trackers;    

Visualforce page:

<apex:page standardController="Opportunity" extensions="TrackerExt">

         <meta charset="UTF-8"/>
              ID: {!OpportunityId}
             Opp: {!trackers[0].Opportunity__c}

      /------Will use trackers list of objects to use for a table here../


I don't get any data in the collection returned. I simply tried to print, use in pageblock and alert in JS. I am adding this page in opportunity page layout.

            var temp = '{!trackers[0].name}';
             var abc = '{!trackers[0].object__c}';
                alert(abc); })();
  • are you passing correct Opportunity Id from URL? – Santanu Boral May 31 '18 at 10:53
  • Thanks Santanu. I am using this page within opportunity page layout. – shukla yogesh May 31 '18 at 10:55

You are trying to access the Tracker__c objects by using merge syntax ({!trackers}). This implicitly looks for a method called getTrackers() in the controller and extensions. I think if you re-name your fetchTracker() method to getTrackers() and get rid of the {get; set;} attribute called 'trackers' you should be fine.

Alternatively you can invoke the fetchTracker() function from within your constructor, which assigns the list to the {get; set;} attribute called 'trackers'.


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.