4

I've created a function that determines if an object is real and (in this case) setting a variable to true/false based in that result. That value is then used to set a vf variable that will later be used to show or hide an html element:

VF page section

<apex:variable var="hideRecurring" value="{!IF(!showRecurring,'hide-content','')}" />

VF Controller

this.showRecurring = Helper.isRealObjectName('npe03__Recurring_Donation__c');

Helper.isRealObjectName

public static Boolean isRealObjectName(String objName) {
    Boolean isReal = false;

    // Call global describe to get the map of string to token.
    Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();

    // Get the token for the sobject based on the type.
    Schema.SObjectType st = gd.get(objName);

    if(null != st) {
        isReal = true;
    }

    return isReal;
}

This works fine in a development environment (showRecurring = true), however in a managed package it does not (showRecurring = false). npe03__Recurring_Donation__c exists in both places.

If I run the isRealObjectName logic in the Developer Console on the server with the managed package, "isReal" = true;

Is there anything in a managed package that would cause this behavior?

8
  • 1
    When it doesn't appear in the Visualforce page, are you running it as the same user where it works in the Developer Console on production. Also, is the managed package the one with the npe03 namespace? It might be that the namespace prefix isn't needed when used within the context on the managed package. Commented Feb 4, 2016 at 0:33
  • 2
    Note that there was also a change in how the namespace prefixes were applied in API v28.0. Accessing All sObjects Commented Feb 4, 2016 at 0:37
  • 1
    I found in Understanding Describe Information Permissions - ". While Partners can request access to standard objects, custom objects are not included as part of the managed package and can never be referenced or accessed by dynamic Apex that is packaged." Commented Feb 4, 2016 at 18:37
  • 1
    In About API and Dynamic Apex Access in Packages - "The developer of an AppExchange package can restrict API access for a package before uploading it to Force.com AppExchange. Once restricted, the package components receive Apex and API sessions that are restricted to the custom objects in the package. The developer can also enable access to specific standard objects, and any custom objects in other packages that this package depends on.". Commented Feb 4, 2016 at 18:40
  • 1
    @DanielBallinger The controller uses with sharing. The other links you provided helped me solve the problem (thank you!!!). Basically, I had to make 'API Access' Unrestricted for my package before I uploaded it. If you'd like to add an answer with that info I'll accept it, or I can add the answer if you don't want to.
    – Dan Bough
    Commented Feb 4, 2016 at 19:13

1 Answer 1

3

As per the comments, the details in About API and Dynamic Apex Access in Packages had the answer.

In particular, with the managed package API Access setting:

The developer of an AppExchange package can restrict API access for a package before uploading it to Force.com AppExchange. Once restricted, the package components receive Apex and API sessions that are restricted to the custom objects in the package. The developer can also enable access to specific standard objects, and any custom objects in other packages that this package depends on.

To access the custom object defined outside of the managed package it needed either unrestricted API access or explicit permissions to the custom object.

You must log in to answer this question.

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