function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Victorino Regpala 5Victorino Regpala 5 

Get opportunity owner display name in REST API call

Hi all,

I am new to Salesforce REST API and I'm trying to get the Opportunity Owner value as shown in the UI thru the REST API.  Calling the REST API will only return the OwnerId and I would like to return value shown in the UI which is the firstname and lastname.  I can actually do this by creating a custom formula field but I was wondering if there is another way to do this without creating a custom field.

Thanks,
Victor
Laxman Vattam 26Laxman Vattam 26
You can query User object using the owner id to get the Name and pass it on
Guy_KeshetGuy_Keshet
to expend on LAxman's response - perfrom another call out to get a user record where user.id = opp.ownerid and use the name fields of the user record
Sumeet_ForceSumeet_Force
while fetching value from the Opportunity through your REST call, use field Owner.Name which would give what you want !
Amit Singh 1Amit Singh 1
While making the REST API call use Owner.Name in your SOQL and for return type use a wrapper class which will return OpportunityId and OwnerName. Wrapper class will be like given below:
public class wrapperResponse{
      public static Id opportunityId {get; set;}
      public static String ownerName {get;set;}
}

 Let me know if this helps for you :)

Thanks,
Amit Singh.