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
CB312CB312 

Need help generating a dynamic query based on values in the current record

Hi,

 

What I'm trying to do:

Generate a custom data table on a page that renders based on the values entered in the record that is currently being viewed. The code compiles with no errors but doesn't output any related leads. The class and vf page are below. Any help would be appreciated.

 

Class:

 

public class POSystem {
    public POSystem(ApexPages.StandardController controller) {}  
    public List<Lead> getPOSystem() {
        
        String Category = ApexPages.currentPage().getParameters().get('Category__c');
        String Subcategory = ApexPages.currentPage().getParameters().get('Subcategory__c');
        id repid = ApexPages.currentPage().getParameters().get('Assigned_To__c');
        
        POSystem = [select company, Category__c, Subcategory__c, Name, Phone, Last_Activity_Date__c from Lead WHERE ownerid = :repid AND Category__c = :Category AND Subcategory__c = :Subcategory ORDER BY company ASC ];
  return  POSystem;
}
}

 VF Page

 

<apex:page standardController="Purchase_Order__c" extensions="POSystem">
  <apex:sectionHeader title="Purchase Order"/>
 <apex:pageBlock title="PO Leads">
  <apex:dataTable value="{!POSystem}" var="l" cellPadding="4" border="1" style="text-align:center">
   
   <apex:column >
    <apex:facet name="header">Lead</apex:facet>
    <apex:outputField value="{!l.company}"/>
   </apex:column>
   <apex:column >
    <apex:facet name="header">Category</apex:facet>
    <apex:outputField value="{!l.Category__c}"/>
   </apex:column>   
  
   
  </apex:dataTable>
 </apex:pageBlock>
</apex:page>

 

Thanks!

 

 

Cory CowgillCory Cowgill

Try sticking some System.debug() lines in your controller.

 

1. Make sure your parameters are coming across in your controller.

2. Make sure your SOQL is returning results.

 

Below is code to add some debug statements. Make sure you have the System Log window (found in upper right under "Setup") open and try to load your VF Page and see what comes out in the console.

 

public class POSystem {
    public POSystem(ApexPages.StandardController controller) {}  
    public List<Lead> getPOSystem() {
        
        String Category = ApexPages.currentPage().getParameters().get('Category__c');
    System.debug('Category Parameter == ' + Category);
        String Subcategory = ApexPages.currentPage().getParameters().get('Subcategory__c');
    System.debug('SubCategory Parameter == ' + SubCategory):
        id repid = ApexPages.currentPage().getParameters().get('Assigned_To__c');
    System.Deubg('Assign To ID Param == ' + repid);
        
        POSystem = [select company, Category__c, Subcategory__c, Name, Phone, Last_Activity_Date__c from Lead WHERE ownerid = :repid AND Category__c = :Category AND Subcategory__c = :Subcategory ORDER BY company ASC ];
      System.debug('POSSystem result size == ' + POSystem.size());
    return  POSystem;
}
}

CB312CB312

Thanks Cory - I guess I am trying to refrence the values incorrecly, do you know how I can access the current values of the record and then store them so they function in the query?

 

String Subcategory = ApexPages.currentPage().getParameters().get('Subcategory__c');

returns 'null'

 

Do I need to query the current page id, then do a soql query using that ID to return the values. I thought the Apex.Page.currentPage function would do that. Or am I missing a step here?

 

Thanks,

Chris

minkeshminkesh

Hello CB312,

                         First i want to ask you that what is that  .get('Subcategory__c') .Is it QueryString Parameter ?

and another thing is try to execute Query using database.query();  it is using to execute dynamic soql query. Let me know if this is helpful.