You need to sign in to do that
Don't have an account?
SOQL Query: Extracting a name for a custom field
I have a custom field (Tenant__c) which represents a lookup value for Accounts. I am trying to write a SOQL query to extract the names in this field, rather than the 18 character case safe value. I know when you are trying to to pull the name for the Account field, you express it as "Account.Name", but I cannot get the correct syntax for this custom field (Tenant.Name__c does not work). What is the correct syntax in this situation? Thank you.
You need to use the Relationship name between the object and Account object in order to get the Accont Name, for example if the Lookup field Tenant__c is present on an Object with API name XZY__c below query can be used to get the Account Name.
Select Tenant__r.Name from XZY__c
Also you can refer the below documentation for more understanding on Relationship queries:
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_query_using.htm#sforce_api_calls_soql_relationships_query_using
Regards,
Akash
All Answers
You need to use the Relationship name between the object and Account object in order to get the Accont Name, for example if the Lookup field Tenant__c is present on an Object with API name XZY__c below query can be used to get the Account Name.
Select Tenant__r.Name from XZY__c
Also you can refer the below documentation for more understanding on Relationship queries:
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_query_using.htm#sforce_api_calls_soql_relationships_query_using
Regards,
Akash