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
ian elrickian elrick 

REST API and SOQL How to retrieve the Displayed "Created By" instead of the createdByID

Hi
I have successfully got a rest call working with bbbbasic fields from the opportunity table as follows:

SELECT Opportunity.Name, OrderNumber__c,Account.Name, Type,StageName, Description,CloseDate from Opportunity where IsClosed = False order by CloseDate ASC LIMIT 100

I want to add other fields to this such as "Created  By" but these are lookups on the User table and including the CreatedById field gives the id as opposed to the meaningfull date. 
Any idea how to do this?

Thanks in advance.
 
Payal Popat 27Payal Popat 27
Hi,

Please use createdby.Name to get the full name of the user who created Opportunity.

Thanks
Ian Elrick 3Ian Elrick 3
Hi

Thanks for this. That is helpful . One more ask? Can you direct me to where the rules for such access are documented? 

I take it to get the displayed value of any lookup column I just retrieve the .Name of the label without spaces?

Thanks again
Payal Popat 27Payal Popat 27
Hi,
 
CreatedBy and Lastmodifiedby are lookup of User object. And in queries, you can refer all the fields of user object using its reference createdby.(user field)
 
You can check lookup fields on your object and accordingly use its reference fields.
Please check the reference links mentioned below:
Lookup field reference: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_lookup.htm

System fields reference: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/system_fields.htm

Please mark the answer as best if it helps you resolve your queries.

Thanks.
Ian Elrick 3Ian Elrick 3
Hi

Thanks. That is superb. I cannot see an option to mark as best. Just to like. Can you advise how to do this please?
Payal Popat 27Payal Popat 27
Please mark the question as solved and then you will get Best Answer link.

Thanks.