0

I can query something like select myCustomField, Owner.Name from myCustomObject, and get the owner's name in the results, which works as expected in a soql query.

However, when I execute this in Apex, it returns a List<myCustomObject>, which does not contain a property for Owner.Name, so the owner value is lost.

I did notice that it does return the OwnerID. Is there any way to return the actual result of this query in Apex, including the Owner information?

2
  • You should be able to access owner name by List[0].Owner.Name, it doesn't returns lookup object's field by default.
    – Raul
    Commented Apr 6, 2017 at 4:56
  • @DougOler, is that my ans solves your issue then please accept so that other can find this useful Commented Apr 6, 2017 at 15:58

1 Answer 1

0

SOQL query returns owner information and you can retrieve owner information from this list like this way:

List<Dealer__c> lstDealer = [SELECT Dealer_Number__c, Name, OwnerId, Owner.Name, owner.type FROM Dealer__c];

if(!lstDealer.isEmpty())
{
    System.debug('owner name=' + lstDealer[0].Owner.Name );
    System.debug('owner type=' + lstDealer[0].Owner.Type);
    System.debug('ownerId=' + lstDealer[0].Owner.Id);
}

You must log in to answer this question.

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