0

I currently have a SOQL line that queries an individual field from a custom object, the name of the field is decimal_since_creation__c, this field counts the number of minutes since the creation of the record. The only problem is, whenever I try to display that field onto my VF page, it combines the values instead of displaying the values individually, how can I fix this?

Here is my code: Note that the particular query in question is minutes

 public without sharing class LeadAlertController {
    public integer leads {get;set;}
    public integer overleads {get;set;}
    public List<lead__c> Names {get;set;}
    public List<lead__c> minutes {get;set;}



    public LeadAlertController() {
        leads = [select count() from lead__c where lead_status__c=:'Not Attempted'];
        overleads=[select count() from lead__c where lead_status__c=:'Not Attempted' AND x10MinAlert__c=:true];
        Names = [select patient_name__c from lead__c where lead_status__c=:'Not Attempted'];
        minutes = [select decimal_since_creation__c FROM lead__c where lead_status__c=: 'Not Attempted']; 


    }
}

Here is what the query is displaying on the VisualForce page:

enter image description here

The value should be an individual number, not the combined value of each record that is listed on the page.

Edit: Here is my VF page code as well

    <apex:page controller="LeadAlertController" showHeader="false" sidebar="false" standardStylesheets="false">
    <!-- Begin Default Content REMOVE THIS -->
    <apex:form >

    <meta http-equiv="refresh" content="10"/>
    <style>
    td{
        border: 1px ;
        border-style: solid;
    }

    </style>
    <table align="center" style="width:100%;border:1px solid">
        <tr>
            <td align="center">
                <h3>Number of Hot Leads</h3>
            </td>
            <td align="center">
                <h3>Number of Hot Leads Over 10 Minutes</h3>
            </td>
             <td align="center">
                <h3>List of Names</h3>
            </td>
        </tr>
        <tr>
            <td align="center">
                <h1>{!Leads}</h1>
            </td>
            <td align="center">
                <h1>{!OverLeads}</h1>
            </td>
             <td align="center">
                <apex:repeat var="lead__c" value="{!Names}">
                <br>
    <apex:outputText value="{!lead__c.Patient_Name__c}"/>
    <apex:outputText value=" "/>



              <apex:repeat var="lead__c" value="{!minutes}">
                <apex:outputText value="{!lead__c.Decimal_Since_Creation__c}"/>
                </apex:repeat>



</br>
</apex:repeat>
            </td>
        </tr>
    </table>

    <apex:outputPanel rendered="{!if(OverLeads>0,true,false)}">
        <audio src="/resource/alert" type="audio/mp3" autoPlay="true">
        </audio>
    </apex:outputPanel>
    </apex:form>
</apex:page>
3
  • Please edit your question to add the VF page markup used as well.
    – Phil W
    Oct 3, 2019 at 14:31
  • Sorry about that, edited to include my VF page code :) Oct 3, 2019 at 14:34
  • I don't understand. Why don't you just query the leads in one query with the patient_name__c and decimal_since_creation__c fields. Then loop through your list and display the name related to the lead and the decimal field. Oct 3, 2019 at 15:09

1 Answer 1

0

Your iteration of the counts was wrongly structured in the VF page. That said, it strikes me as far better to leverage presentation of the actual Lead__c instances, obtained in one query, like this:

Controller:

public without sharing class LeadAlertController {
    private static final Integer maxLeadsShown = 30; // Think about UX. Don't show too much data

    public Integer numberOfLeads { get; private set; }
    public Integer numberOfOverLeads { get; private set; }
    public List<Leads__c> unattemptedLeads { get; private set; }

    public LeadAlertController() {
        numberOfLeads = [SELECT COUNT() FROM Lead__c WHERE Lead_Status__c = 'Not Attempted'];
        numberOfOverLeads = [SELECT COUNT() FROM Lead__c WHERE Lead_Status__c = 'Not Attempted' AND x10MinAlert__c = TRUE];

        unattemptedLeads = [SELECT Id, Patient_Name__c, Decimal_Since_Creation__c FROM Lead__c WHERE Lead_Status__c = 'Not Attempted' LIMIT :maxLeadsShown];
    }
}

(Note I tidied up the SOQL syntax to use preferred case and to remove unnecessary use of binding variables.)

Then in the VF page:

<apex:page controller="LeadAlertController" showHeader="false" sidebar="false" standardStylesheets="false">

    ...

    <td align="center">
        <h1>{!numberOfLeads}</h1>
    </td>
    <td align="center">
        <h1>{!numberOfOverLeads}</h1>
    </td>
    <td align="center">
        <apex:repeat var="lead" value="{!unattemptedLeads}">
            <br />
            <apex:outputText value="{!lead.Patient_Name__c}"/>
            <apex:outputText value=" "/>
        <!-- I don't see it makes sense to leave this iteration open here, so closed -->
        </apex:repeat>
    </td>
    <td>
        <apex:repeat var="lead" value="{!unattemptedLeads}">
            <apex:outputText value="{!lead.Decimal_Since_Creation__c}"/>
        </apex:repeat>
    </td>

Now, that said, I don't think this corrects your formatting - I think you should have a single row per lead. Further, I think you should consider using other markup for this. You could use data table presentation for example. Check the documentation to find out what various built-in features you could be using.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .