0

I have below code which compiles fine but UserTemp which is List returns null.

Can someone suggest what is the root cause? SOQLs are fine to return values.

Code

 get
        {   terrid = [select UserId, TerritoryID from Userterritory where UserID=: UserInfo.getUserId()].TerritoryID;
            ParentTerr = [select Parentterritoryid,ID from territory where ID=: terrid].Parentterritoryid;
            List<territory> territoryList= [select Parentterritoryid,ID from territory where ID=: ParentTerr ];
                if(territoryList!=null && !territoryList.isEmpty()){
                     PterrId = territoryList.get(0).Parentterritoryid;
                }

            List<userterritory> DMUser= [select UserId,territoryid from userterritory where territoryid =: ParentTerr];
              if(DMUser!=null && !DMUser.isEmpty()){
                     DM = DMUser.get(0).UserId;
                }
           // DM = [select UserId,territoryid from userterritory where territoryid =: ParentTerr ].UserId;
            if(PterrId!=null)
            RM = [select UserId,territoryid from userterritory where territoryid =: PTerrId ].UserId;
            Set<Id> UID = new Set <Id> ();
            UID.add(DM);
            UID.add(RM);
           UserTemp=[select Name , Id , Email from User where Id in : UID];


            UserEmail=[select email from user where id = :UserInfo.getUserId()].Email;

         //   UserTemp = [Select u.LastName, u.Id, u.FirstName, u.Email From User u limit 1];

            UserList = new List<SelectOption>();

            for(User temp : UserTemp)
            {
                UserList.add(new SelectOption(temp.Id, temp.Email));

            }
            return UserList;
4
  • SFDC Like Ravikant said check if your set contains value or not UID use system.debug('--------'+UID);.. I think code looks good to me if you dont get any error. May be you need to rerender your page code.
    – Ratan Paul
    Feb 17, 2016 at 9:40
  • 1
    Extreme sorry , my DI team has missed out the load. So SOQL returned no data. Sorry Feb 17, 2016 at 9:43
  • SFDC Learner no need to say sorry. Good you solved your question..
    – Ratan Paul
    Feb 17, 2016 at 9:44
  • I am assuming userterritory is a Junction object and how you are handling if there are multiple Users returned by the query? Feb 17, 2016 at 10:19

1 Answer 1

5

Please apply system.debug('###########'+UID); before below line and check UID Is as a blank , I think UID is returning blank value in your case.

 Set<Id> UID = new Set <Id> ();
 UID.add(DM);
 UID.add(RM);
 system.debug('###########'+UID); 

 UserTemp=[select Name , Id , Email from User where Id in : UID];
6
  • 2
    I think this would better go as comment Feb 17, 2016 at 9:42
  • Cool looks like that is the cause. +1 Feb 17, 2016 at 9:45
  • Can anybody explain why my this answer is down voted? Feb 17, 2016 at 11:00
  • 1
    I down voted it and should have explained why. Firstly UID can never be null as it is initialised a couple of lines before the query. (Perhaps the real issue is the values the set contains.) Secondly the query may return zero rows but will never return null so it would be worth clarifying that for the OP to help them become more self sufficient. And I also +1 that this would have been more appropriate as a comment.
    – Keith C
    Feb 17, 2016 at 12:05
  • Hi Keith C I have updated my answer, please take a look. Feb 17, 2016 at 13:51

You must log in to answer this question.

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