How can query Opportunity Owner Name?

I tried:

public List<Opportunity> opportunity{get;set;}

opportunity = [SELECT Name,OwnerId
                       FROM Opportunity

But I only need first and last name.

1 Answer 1


Can you use the below query. Ownerid will return only the id of the owner. You have to use Owner.name as below.

SELECT id ,name,owner.Name,ownerid from opportunity
  • It worked, but why gave out the same name many times in a row, how to make it show only once?
    – Andrew
    Dec 21, 2021 at 9:47
  • Do you want that for single opportunity? If that is the scenario you have to use the where condition in the query. Dec 21, 2021 at 9:49
  • And what should be in where?
    – Andrew
    Dec 21, 2021 at 10:04
  • Can we know what exactly you are trying to do . Please edit the question and mention what exactly is required. Are you trying to use the standard controller? Dec 21, 2021 at 10:25
  • I'm trying to create an invoice and I just need an Opportunity Owner Name. Just to have it shown and that's it.Yes I am using a standard controller
    – Andrew
    Dec 21, 2021 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.