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
Btuitasi1Btuitasi1 

Extension: List based on page ID

I have a visualforce detail page that utilizes a link like: 

https://org-developer-edition.na17.force.com/MyCommunity/Page_Detail?id=a00o0000007FxHjSSK

I am trying to construct a controller that would allow me to display a record from a custom object (Idea Comments) with a master-detail relationship to the standard controller object (Idea Lobby) based on the ID of the displayed record.

Here is my extension so far:
public with sharing class detExt { 
public detExt(ApexPages.StandardController acon) { } 
public List<Idea_Comments__c> getdetExt() 
{
    return [SELECT Id, CreatedDate, CreatedBy.Name, Comment__c 
    FROM Idea_Comments__c 
    WHERE Idea_Lobby__c = 
    order by CreatedDate DESC ]; 
}
}



I only want the Idea Comment records with the master-detail relationship to the specific record to show up.

Thanks!!
Best Answer chosen by Btuitasi1
BalajiRanganathanBalajiRanganathan
you  have to use ApexPages.currentPage().getParameters().get('id') to get the Id.
public with sharing class detExt { 
List<Idea_Comments__c> detExt = null;

public detExt(ApexPages.StandardController acon) { } 
public List<Idea_Comments__c> getdetExt() {
  if (detExt != null) {
    return detExt;
  }
    
detExt = [SELECT Id, CreatedDate, CreatedBy.Name, Comment__c 
    FROM Idea_Comments__c 
    WHERE Idea_Lobby__c = : ApexPages.currentPage().getParameters().get('id')
    order by CreatedDate DESC ]; 
 return detExt;
}
}

All Answers

BalajiRanganathanBalajiRanganathan
you  have to use ApexPages.currentPage().getParameters().get('id') to get the Id.
public with sharing class detExt { 
List<Idea_Comments__c> detExt = null;

public detExt(ApexPages.StandardController acon) { } 
public List<Idea_Comments__c> getdetExt() {
  if (detExt != null) {
    return detExt;
  }
    
detExt = [SELECT Id, CreatedDate, CreatedBy.Name, Comment__c 
    FROM Idea_Comments__c 
    WHERE Idea_Lobby__c = : ApexPages.currentPage().getParameters().get('id')
    order by CreatedDate DESC ]; 
 return detExt;
}
}
This was selected as the best answer
BalajiRanganathanBalajiRanganathan
you can remove with sharing from the class definition if you want the data to visible to everyone