+ Start a Discussion
Srinivas223Srinivas223 

how to execute a if condition for a user and his manager?

Hello All,

I have a situation where i have to return a list of records for the logged in user and his manager if he logs in based on the criteria in the if condition.
code here:
 string userid = userinfo.getuserid();
user u = [select id, name, Managerid from user where id =: userid];
if(StatementName  == '2017'+'-'+'YTD'+'-'+u.name )
 return [select id,CompStatement__c,Name,Delivery__c,RecordTypeId,RecordType.Name,Award__c,CompStatement__r.name,Notes_Comments__c from CompStatementLineItem__c where  CompStatement__r.name like :'2017%' and CompStatement__r.SalesPersonCompMgr__r.name =: u.name ];
                else if(StatementName  == '2018'+'-'+'YTD'+'-'+u.name)
                return [select id,CompStatement__c,Name,hip__r.aircraft__c,Notes_Comments__c from CompStatementLineItem__c where  CompStatement__r.name like :'2018%' and CompStatement__r.SalesPersonCompMgr__r.name =: u.name];               
        else
            return [select id,CompStatement__c,Name,Delivery__cNotes_Comments__c from CompStatementLineItem__c where CompStatement__c = :statementId];

i want to return the values for the first and second if statements for the user and his manager if the manager logs into.
How do i check the logged in user for the manager of a user?
I appreciate your suggestions
Thank you
v varaprasadv varaprasad
Hi srinivas,
Please check once following query to retieve manager name.
 
​User us = [select id,Name,UserRole.Name,Manager.name from user where id=:UserInfo.getUserId()];
if(StatementName  == '2017'+'-'+'YTD'+'-'+u.name  && u.Manager.name == 'ManagerName')

Hope this helps you!


Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
 
Srinivas223Srinivas223
Hello Varaprasad,

I tried this way. but how to return the values for the manager too. Each salesrep should be able to see his year to date commissions. I am checking the current user with userinfo() and adding it to the statement name and returning the results with a query. but these results are not visible to the manager as I used userinfo() in the beginning.
Could you please provide the solution.
I appreciate your response.