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
Jeremy DeseezJeremy Deseez 

List of User Id in a List with the Forecasting Quota

Hi,
I have a List of User Id :
List<User> resultsusers = new List<User>();
		resultsusers = [SELECT Id FROM User WHERE IsActive = TRUE AND ForecastEnabled = TRUE];
And a List of ForecastingQuota :
List<ForecastingQuota> resultsquotas = new List<ForecastingQuota>();
	    resultsquotas = [SELECT Id,QuotaAmount,QuotaOwnerId FROM ForecastingQuota ORDER BY StartDate ASC];
And I want to put the Id of the User with the Id of the ForecastingQuota and also his QuotaAmount in a new List.

I don't know how to make it.

Thanks for  your reponses :)


 
bob_buzzardbob_buzzard
You already have the forecastingquotes in a list with the quotaamount and the quota owner id - the resultsquotas is exactly that.



 
Jeremy DeseezJeremy Deseez
Hi, But i also want thé users Who haven't got yet a quota Regards
bob_buzzardbob_buzzard
In that case I'd do the following:
 
// put the forecastquotas in a map keyed by owner id
Map<Id, ForecastQuota> fqsByOwnerId=new Map<Id, ForecastQuota>();
for (ForecastQuota fq : resultquotas)
{
    fqsByOwnerId.put(fq.QuotaOwnerId, fq);
}

// new map of quotas keyed by all user ids
Map<Id, ForecastQuota> allUserFqsByOwnerId=new Map<Id, ForecastQuota>();
for (User u : resultsusers)
{
      allUserFqsByOwnerId.put(u.id, fqsByOwnerId.get(u.id));
}

Now you have a map of forecast quotas where the keys are the ids of all users. If you have a user without a quota then retrieving it from the allUserFqsByOwnerId map will return null.

Caveat emptor - I haven't compiled or tested this code, but it should get you started.
Jeremy DeseezJeremy Deseez
Ok now I understand the "Map".
So can i return a Map ?

 
bob_buzzardbob_buzzard
You can return a map, or you can iterate the keys and take appropriate action based on whether there is a quota or not.
Jeremy DeseezJeremy Deseez
Thanks Bob, that's work, but I also want to return the user with no quota, and the Map just return the user with Quota.
How can I return also the User with no Quota in the same List ?

Regards