+ Start a Discussion
OnDem DevOnDem Dev 

How to find Manager of a User using Forecast hierarchy?



All users in my org have the Manager field empty.

We are using Forecast Hierarchy in our org to share the data.


Now my requirement is to find Manager of a User using Forecast Hierarchy.

I am not using the Standard Role hierarchy.


Is there any solution to this?

Will ForecastShare object be of ay help in achieving this?


Any help on this will be highly appreciated.



Message Edited by OnDem Dev on 10-02-2009 01:02 AM

The RevenueForecast object (or the QuantityForecast depending on which you are using) stores the managerid value for a users forecast.

You could query that object for a current period entry for the user, and you would be able to get the ManagerID field, which you could then query to get the user data for that manager.

OnDem DevOnDem Dev

Thanks for the response.


When i am rying to query that object, its returning nothing.

When i tried to query ManagerId, its throwing an exception 'Didn't understand relationship in the fieldpath'.



Can you please let me know what actually i am missing.




Which Forecast method are you using in your instance?  In the forecast settings part of setup, you need to select either "Quantity" or "Revenue", that will determine which object gets populated.


I can do a query as simple as this one and pull back records:



Select r.PeriodId, r.Owner.Name, r.OwnerId, r.ManagerId, r.Id From RevenueForecast r

 Could you post your query that is generating the error?



OnDem DevOnDem Dev

Thanks for the reply.

By just enabling the Revenue Forecast in the Forecast settings, will that populate the RevenueForecast object.


Can you please let me know is that enough or anything else has to be done?




I am not sure about that, I assumed that if you were already sharing object access via the forecast hierarchy, you had it enabled.  We are using custom forecasting in our org, and those records are populated.  I don't believe we had to do anything else.  You might want to make a support call to get clear direction on this before you make any changes.

Sorry I can't be more help.

OnDem DevOnDem Dev

Thanks Jim for all your answers.


Made all the changes in the Forecast settings and enabled the Customizable Forecast Hierarchy.


Now, query to the RevenueForecast object is below.

RevenueForecast[] rf = [select ManagerId, Quota from RevenueForecast];


When i tried to find the size its returning zero. So the object is empty.


Can you please let me know why the Revenue Forecast object is empty even after selecting in the Forecast settings?

Am i missing out anything.


Help me with your valuable suggestions to overcome the issue.




I am a bit confused about your situation. I thought you were already using the forecasting module.  You indicated you were already doing sharing via the Forecast Hierarchy, which I assumed meant you had forecasting enabled.

I hope our conversation has not inadvertantly added additional complexity to your solution.


So, if you are using custom forecasting, you need to create quota records for each of your users, one for each period you are going to forecast in.  We do quarterly, for your purposes, maybe annual would be sufficient.

You can even leave the quota amount at 0 if you want.

This will create entries in the revenueforecast object that will get updated with the data from the opportunity records for the amount, and will include the manager from the Forecast heirarchy.

OnDem DevOnDem Dev

Thanks Jim,


Sorry for troubling a lot.

I am new to Forecast hierarchy, so finding it tough to understand.


I did the same by adding Quota value for a Period. I guess i am near the solution.

When i query without ManagerId field, i get all the Quota values from the RevenueForecast object.

When ManagerId field is queried, the queru returns zero records.


Can you please let me know what could be the reason?



It works for me. Could you share the queries that you are running?
OnDem DevOnDem Dev


With ManagerId, the query is below 

RevenueForecast[] rf = [select ManagerId, Quota from RevenueForecast];

Without ManagerId,

RevenueForecast[] rf = [select Quota from RevenueForecast];

Then i used Ajax Tools to test whether the query is working or not,

SELECT Quota, Manager.Name FROM RevenueForecast


But got below error mesage 

INVALID_FIELD: SELECT Quota, Manager.Id FROM RevenueForecast ^ ERROR at Row:1:Column:15 Didn't understand relationship 'Manager' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names


Can you please tell why is this happening?



Message Edited by OnDem Dev on 10-06-2009 11:13 PM

Now I understand.  When you were saying ManagerId I thought you meant the managerid field. There is no Foreign key relationship called Manager, so you can't query for Manager.id.


You need to do 2 queries, one to get the list of managers, and a second to get the manager name.  Depending on your use case, you would either create a map of all managers to their related user, or could just query for single manager you are looking for.



String MgrID = [select managerid from Revenueforecast limit 1].managerid;

//change this query to look for the manager ID of a particular user with

//the 'where ownerid = xxxxxxxxxxxxx' user Mgr = [select name from user where id=:MgrID]; system.debug(Mgr);




OnDem DevOnDem Dev

Thanks once again.


I did the same, now its returning ManagerId as null.

I check it in Ajax Tools.


What could be the issue now?

I am really thankful to your responses that helped me understanding.



You have me stumped.  When you do a full query of the RevenueForecast object you can see the managerid, but when you just query the managerid by itself, it is null.  I think you may have a bug, I would recommend you contact support.
OnDem DevOnDem Dev

OK, i will do that Jim.

Thanks for all the help you provided.