[SalesForce] Active User and their related Tasks SOQL

I want to fetch the list of active User and their list of Task records.

Following Query works for me to fetch all Task records with an active User

select 
    Id,
    Subject, 
    Status, 
    OwnerId,
    Owner.Name,
    Owner.IsActive
from Task 
where OwnerId in (select Id from User where isActive = true)

Thanks to @BarCotter.

Now, I want Total and Completed counts of Task records for each User separately and print the results in Visualforce.

Visualforce

<table>
    <apex:repeat value={!listUser}>
       <tr><td>
          <input type="text" class="myJSClass" value="{!taskPercentage}"/> 
        </td></tr>
    </apex:repeat>
</table>

Apex Method

public Double getTaskPercentage(){
    // *** HERE I want to calculate the Tasks Percentage like
    Double tpercent = (taskcompleted * 100)/totaltask;
    return tpercent;
}

I am thinking of using apex:actionFunction but I am little confused today with the basics.

Best Answer

Perform SOQL and create Map by results

Related Topic