2

I have an object id that is a "parent id" of a specific Attachment object (e.g., b3KD0000119wDTlMAN). I'd like to understand what type this object belongs to, to query for it's details. It can also be a Custom Object. Currently I only work through REST API. Can this be done using REST API?

1
  • Take a look at my answer for a more direct solution.
    – sfdcfox
    Commented Feb 27, 2015 at 16:51

3 Answers 3

2

You can query the parent's type directly in the SOQL:

SELECT ParentId, Parent.Type FROM Attachment WHERE Id = ...

You'll get a response like this:

{
    "done": true,
    "records": [
        {
            "attributes": {
                "type": "Attachment",
                "url": "/services/data/v33.0/sobjects/Attachment/..."
            },
            "ParentId": "...",
            "Parent": {
                "attributes": {
                    "type": "Name",
                    "url": "/services/data/v33.0/sobjects/Opportunity/..."
                },
                "Type": "Opportunity"
            }
        }
    ],
    "totalSize": 1
}
2
  • Thanks a lot sfdcfox. This is a much better solution indeed. Commented Mar 1, 2015 at 10:00
  • yes i agree, i was not aware about this thanks @sfdcfox
    – Harshi
    Commented Mar 1, 2015 at 15:17
0

You can get object type by Id using dynamic apex

Schema.SObjectType token = objIds[0].getSObjectType();

where objIds is a list of Ids.

Read more on this link.

You have to add all these methods (as per your requirement) in your REST service provider class.

-1

As far as i know there is no such function available but you can create your own library to find object using first 3 letter of id here is the list for some standard salesforce object.https://help.salesforce.com/apex/HTViewSolution?id=000005995&language=en_US

1
  • 1
    You should be able to query parent.type in the query.
    – sfdcfox
    Commented Feb 27, 2015 at 16:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .