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
Christopher_JChristopher_J 

Extension Controller Question

Hi All,

 

Still very new to apex and visualforce so back with basic questions that I can't find the answers to.  Thanks in advance for any help that can be offered.

 

I'm having an issue with a SOQL query in my extension controller.  Basically what I'm trying to do is a create a list of custom object records (pricing_exception__c) in an embedded visualforce page on the opportunity layout.

 

I have the section created fine in visualforce but I can't get the list to come back correctly.  My code is as follows.  The ????????? needs to essentially be account.name of the opportunity page I'm on but nothing I'm trying is producing a result.  I'm starting to wonder if it's not possible to do this with an embedded vf page in the opportunity layout?

 

public class retrievePEList {

public retrievePEList(ApexPages.StandardController controller) {

}

 

public List<Pricing_Exception__c> getExceptions() {
return [SELECT Name, Pricing_Exception__c.Account_Name__c, End_User_Account_Name__c, PE_Status__c, Exception_End_Date__c FROM Pricing_Exception__c
WHERE PE_Status__c = 'Approved' and Exception_End_Date__c > TODAY and ???????????

}
}

ICSteveICSteve

You will need to query for the record or account in order to get Account.Name. Normally you could just use the record included in the StandardController but that will not work for fields on another object. You can do something like this:

 

public class retrievePEList {

private String accountName;

 

public retrievePEList(ApexPages.StandardController controller) {

accountName = [SELECT Name FROM Account WHERE Id = :controller.getRecord.get('ACCOUNTFIELD')].Name;

}

 

Then, compare against accountName in your query.

Christopher_JChristopher_J

Sorry I might not have explained this adequately or I may be misunderstanding your response.

 

I've created an embedded visual force section on the Opportunity layout.  From my understanding account.name is how you refer to the name of the account the opportunity is associated with.  The visualforce page uses the opportunity controller and this is an extension controller I'm calling to list the pricing exceptions associated to the account that the opportunity is associated to.  So the final part of the query needs to essentially say the name of the pricing exception (name) = the account name (account.name) that is associated to the opportunity I'm loading the embedded visualforce section on.  Not sure if that helps.