You need to sign in to do that
Don't have an account?
Drcete
Hot to get related tables' Name values via sObject API?
Hello,
I'm using the sObject Rest API from an external app to get record values.
I need to get the Name values for related tables (reference fields).
Is this possible using this API?
Some alternatives I'm considering are:
-Building a dynamic query and passing it to the query API.
-Creating a custom rest method that returns all fields and related fields' names.
I would prefer to keep the sObject API if possible because the other options require many changes in my app.
What would you recommend?
Thanks!
All Answers
You need to describe call
for ( Schema.SObjectType o : Schema.getGlobalDescribe().values() )
{
Schema.DescribeSObjectResult objResult = o.getDescribe();
system.debug( 'Sobject: ' + objResult );
system.debug( 'Sobject API Name: ' + objResult.getName() );
system.debug( 'Sobject Label Name: ' + objResult.getLabel() );
}
Run this code in Execute anonymous and check debug. You will get all the sobject name(API Name), label and other properties.
If it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
Hello Abhishek,
Yes, I know this is possible. I'm already able to obtain the table schema via a custom Rest API call.
What I need to do now is obtain record data, including reference field names.
I guess I'll have to generate a SOQL query dynamically (using the schema I already have) and do a call to the query API.
It is possible to query related table fields:
SELECT id,Name, Account.Name FROM Contact
/services/data/v50.0/query/?q=SELECT+id,Name,Account.Name+FROM+Contact
I was just wondering if there is a setting on the sObject rest API to make it include Name values for reference types.
Thanks.