You need to sign in to do that
Don't have an account?
Sanjeev Kumar 20
Getting reports based on objects type in SOQL
Hi All !
Can anyone tell me how to get reports based on objects type in SOQL?
I'm trying to fetch from Report Object. But some how I want to fetch only those who belongs to a specific standard/custom object.
for example :
My current query is ->
SELECT Id, Name FROM Report WHERE Format='Tabular' Order by Name limit 10000
All I want is to apply a report type kind of filter so that I can get reports for a specific object (contact, account or custom object etc).
Can anyone tell me how to get reports based on objects type in SOQL?
I'm trying to fetch from Report Object. But some how I want to fetch only those who belongs to a specific standard/custom object.
for example :
My current query is ->
SELECT Id, Name FROM Report WHERE Format='Tabular' Order by Name limit 10000
All I want is to apply a report type kind of filter so that I can get reports for a specific object (contact, account or custom object etc).
Yes, as Ramu told you, you cannot get report type from SQOL.
However, from Metadata API it is possible.
You can start from here (https://github.com/financialforcedev/apex-mdapi/blob/master/apex-mdapi/src/classes/MetadataService.cls) (class to work with metadata):
Basically, you have to call Metadata API in the following sequence:
- Connect to API with session ID of current user. This user should have “Modify All Data” permission.
- Call listMetadata() method to find folders for type 'ReportFolder'
- Use full name of folders to find reports (listMetadata() call, ListMetadataQuery.folder = full name of folder, ListMetadataQuery.type_x = 'Report')
- Use list of report full names to get report metadata - call readMetadata() for type 'Report'
- In the result array you will find property reportType for each item. This is what you need.
Note: Standard object names will be as is e.g. Opportunity, Account etc. Names of custom object will be in format similar to CustomEntity$Merchandise__c (where CustomEntity$ is a prefix).Could you please share some examples or related links.
Thanks,
Sanjeev
Basic documentation you can find by the following link:
https://www.salesforce.com/us/developer/docs/api_meta/
Also look at the following example of code: