0

I'm trying to retrieve record values of a managed package custom object (call it abc__custom_object__c, where 'abc' is the package namespace, as an example). Trying to run the following SOQL query returns the error 'sObject type 'abc__custom_object__c' is not supported':

SELECT Name FROM abc__custom_object__c

I've also tried :

Schema.SObjectType targetType = Schema.getGlobalDescribe().get('abc__custom_object__c');

Which gives a NullPointerException when I try to use the variable targetType. Is there a way to retrieve record information from 'abc__custom_object__c' from apex if 'abc__custom_object__c' is part of another managed package?

So far I've just been running code in an Execute Anonymous window and using Query Editor so I don't have more Apex code to share at this point in time.

'abc__custom_object__c' is part of a third-party managed package I have installed from AppExchange.

EDIT: changed 'custom__object__c' to 'abc__custom_object__c' in example to make the inclusion of the namespace more clear.

3
  • Please use package name space before the object name it will work fine. for example abc__custom__object__c, if still doesn't work. update your question with your soql so I can see what's the problem with that
    – Gopal
    Jun 20, 2023 at 15:48
  • Sorry, in the example 'custom' was supposed to be the package namespace, I've edited the question to make that more clear
    – lhh13
    Jun 20, 2023 at 15:51
  • Are you able to see this object in Object Manager?
    – Gopal
    Jun 20, 2023 at 16:26

2 Answers 2

1

To query managed package custom objects in Apex, you can follow these steps:

  1. Determine the namespace prefix of the managed package. The namespace prefix is usually provided by the managed package provider and is used to uniquely identify the custom objects within the package. It is typically a short string followed by double underscores, such as "abc__".

  2. Build the object name by appending the namespace prefix to the custom object name. For example, if the custom object name is "MyObject__c" and the namespace prefix is "abc__", the resulting object name would be "abc__MyObject__c".

  3. Use the object name in the SOQL (Salesforce Object Query Language) query to retrieve records from the managed package custom object. Here's an example query:

List<abc__MyObject__c> myObjects = [SELECT Id, Name, CustomField__c FROM abc__MyObject__c];

In this example, we are querying the Id, Name, and CustomField__c fields from the abc__MyObject__c custom object. You can modify the query to include or exclude other fields as needed.

Let me know if still it doesn't work

2
  • Apologies, I've reworded my question to make it more clear but in my example I've treated 'custom' as the package namespace, so in the above exampels that would be included. I am trying to call these objects from outside of the managed package, so this is a third party package I've downloaded and now I'm trying to query its objects.
    – lhh13
    Jun 20, 2023 at 15:52
  • 1
    The CustomField__c would be a subscriber added one. To get one from the managed package, it must be abc__CustomField__c.
    – Phil W
    Jun 20, 2023 at 15:53
1

So the issue in this case is that the object in question is a protected custom settings object, which as far as I understand is inaccessible outside of the managed package.

You must log in to answer this question.

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