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?

  • Take a look at my answer for a more direct solution. – sfdcfox Feb 27 '15 at 16:51

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
  • Thanks a lot sfdcfox. This is a much better solution indeed. – Dima Stopel Mar 1 '15 at 10:00
  • yes i agree, i was not aware about this thanks @sfdcfox – Harshit Mar 1 '15 at 15:17

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.


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
    You should be able to query parent.type in the query. – sfdcfox Feb 27 '15 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.