1

In our custom object, when a record is approved (by the Line Manager of the originating owner/user), the owner is changed to the Systems Change Request queue so that the request can be reviewed before proceeding as a project...

But the owner (owner_-c) field of the record in my VF page is showing as blank when viewing the record.

So how can I change my VF code to show the queue name if the owner is a queue, otherwise show the owner (as it does now)

<tr>
    <td class="LeftColumnTop W40" style="text-align: left !important">
        <font class="MainPanelFont">
            <apex:outputLabel value="{!$ObjectType.Request_for_System_Change__c.fields.Owner_Name__c.Label}" />
        </font>
    </td>
    <td class="RightColumnTop W60" style="text-align: left !important">
        <apex:outputText styleclass="MainPanelFont" value="{!OwnerName}" /> 
    </td>
</tr>

In my controller I have the below code to return either the owner__c field or the name of the queue

public string getOwnerName(){
//string ownerType=[select owner.type from Request_for_System_Change__c].type;

//  if (ownerType=='User'){
//      return sObjectRFC.Owner_-c;
//  }
//      else
//      {
//          string QueueName=[]
//      }

Map<String,String> idOwnerNameMap = new Map<String,String>();
//(String)(sObjectRFC.OwnerId).substring(0,3)
ID ownerId=[Select Id,ownerId from Request_for_System_Change__c where Id=:recordId].ownerId;

String OwnerIdsub=  String.valueOf(ownerId);
system.debug('getOwnerName OwnerIdsub:' + OwnerIdsub);

String OwnerName ;
// check that owner is a user (not a queue)
if(OwnerIdsub.substring(0,3) == '005' ){
    OwnerName =  idOwnerNameMap.get(sObjectRFC.OwnerId);                }

// check that owner is a queue
else if(OwnerIdsub.substring(0,3) == '00G' ){
    OwnerName =  idOwnerNameMap.get(sObjectRFC.OwnerId);
   }    

system.debug('getOwnerName OwnerName:' + OwnerIdsub);
return OwnerName;
}

but it's still returning a blank when the owner is a queue

In the debug I get this:

11:31:48:589 USER_DEBUG [105]|DEBUG|getOwnerName OwnerName:005200000028h6TAAQ

so where am I going wrong, and how can I get the name of the queue when it's a queue?

1 Answer 1

1

Query owner.Name

ID ownerId=[Select Id,ownerId, owner.Name  
             from Request_for_System_Change__c where Id=:recordId].ownerId;

And check owner.Name debug

2
  • so to get the name of the queue owner is it: string oName=[Select Id,ownerId, owner.Name from Request_for_System_Change__c where Id=:recordId].owner.Name; ? Jan 26, 2016 at 11:52
  • @OurManInBananas Yes
    – Ratan Paul
    Jan 26, 2016 at 11:53

You must log in to answer this question.

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