+ Start a Discussion
notsosmartnotsosmart 

Referencing page values in controller extension

I have queries in my controller that reference page values in the where clause.  They pass syntax but return no rows.

The only page reference I've been able to use successfully is id.

 

A snipet of one:

 

account = [SELECT Name,
( SELECT Contact.Name, Contact.Email
FROM Account.Contacts)
FROM Account
WHERE Name = :ApexPages.currentPage().getParameters().get('company__c')];

 

This is based on an example but changed from Id = :ApexPages.currentPage().getParameters().get('id')];

 

Is there a call I need to make  to make the fields available?  Or is there another approach.

 

Thanks

sfdcfoxsfdcfox

Not sure what you're trying to do. You can access the page's StandardController by using the single-parameter class constructor (e.g. MyExt(ApexPages.StandardController controller)). You can't directly access other extensions' data except through static references. I'm not sure what "Company__c" is supposed to be, but assuming it were a field available on the standardcontroller, you would generally access it by casting StandardController.getRecord() into a SObject of the expected type. For example:

 

public MyExt(ApexPages.StandardController controller) {
  contact c = (contact)controller.getrecord();
  // Find other contacts at the same company
  contact[] othercontacts = [select id,name,email from contact where company__c = :c.company__c];
}