1

I have an component which will display all opportunity records created today and whose amount is greater than 50000.

I am not able to see any data when I preview the visualforce page.

controller code:

public String accID{get;set;}
public List<Opportunity> oppList{get;set;}
public List<Opportunity> getoppList()
   {
     if (oppList == NULL)
     {
      accID=ApexPages.currentPage().getParameters().get('ID');
       oppList=[select Name,Account.Name,StageName,Amount,CloseDate from 
                Opportunity 
                where 
                AccountID=:accID;
                AND 
                Amount >= 50000
                LIMIT 10000];
     }
  return oppList;
    }

The component is as follows:

<apex:component controller="acctTemplate"
                access="global">

  <apex:attribute assignTo="{!accID}"
                  name="AccountID"
                  description="ID of the Account"
                  type="String"/>
<apex:repeat value="{!oppList}" 
                     var="opp">
        <tr>
            <td>{!opp.Name}</td>
             <td>{!opp.Account.Name}</td> 
</apexrepeat>

I am calling this component inside as visualforce page as follows:

<apex:page sidebar="false">
  <c:opptylist></c:opptylist>
</apex:page>
1

issue here 2 variable with same name i.e. oppList and getoppList. both variable can access in vf using {!oppList } that's the issue.

below code should fix the issue

public String accID{get;set;}

public List<Opportunity> getoppList()
{
      accID=ApexPages.currentPage().getParameters().get('ID');
      return Database.Query('select Name,Account.Name,StageName,Amount,CloseDate from'+
                            ' Opportunity  where AccountID=:accID '+
                            ' AND Amount >= 50000 LIMIT 10000 ');
}

OR

private List<Opportunity> lstOpp;
public List<Opportunity> getoppList()
{
     if (lstOpp== NULL)
     {
       accID = ApexPages.currentPage().getParameters().get('ID');
       lstOpp = [select Name,Account.Name,StageName,Amount,CloseDate from 
                        Opportunity 
                        where 
                        AccountID=:accID;
                        AND 
                        Amount >= 50000
                        LIMIT 10000];
     }
     return lstOpp;
 }
  • 1
    Close enough, but there's no need for the temporary variable-- or it should be global so you only query once. – sfdcfox Oct 11 '16 at 4:05
  • @ratan, I made the changes,its not working either way. Under an account, I created a few opportunity records and then preview the vf page but no data is displayed. am I doing right thing?Also I removed the where condition , but not working. – Pooja Biswas Oct 11 '16 at 4:21
  • @PoojaBiswas can you pls add updated code in your question? – Ratan Paul Oct 11 '16 at 4:32
  • @Ratan,Is it permitted if I move the discussion to a chat? – Pooja Biswas Oct 11 '16 at 4:37
  • @PoojaBiswas no you don't hv much reputation for chat – Ratan Paul Oct 11 '16 at 4:48

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.