function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jlojlo 

Error: Compile Error: Package Visibility: Type is not visible

I just ran in to a problem where I was trying to reference Apex code that lived in a Managed Package, and even though I had the correct syntax, I just couldn't get my code to compile properly. I'd like to share the solution with you.

 

 Here's a simplified version of the code that was frustrating me:

 

public class PackageExtenderClass{

public PackageExtenderClass(){
}

public String myExtenderMethod(){
String temp = myNamespace.UtilityClass.getRandomString();

return temp;
}
}

 

 The above code is correct in every way, but I couldn't get it to compile - I kept getting this error:

Error: Compile Error: Package Visibility: Type is not visible: utilityclass at line 7 column 26

 

It turns out that in order to solve this problem, I needed to update the Version Settings for my PackageExtenderClass so that it referenced the 1.6 version of the 'myNamespace' Managed Package instead of the older 1.3 version. This is becuase the 1.3 version of the Managed Package didn't include a definition for the getRandomString() method. The getRandomString() method was only added in the 1.6 version of the Managed Package.

 

Best Answer chosen by Admin (Salesforce Developers) 
xnxn

Daniel,

From Setup | Develop | Apex Classes | <Your Class> | [Edit], you can edit the dependency information on the Version Settings tab.  Alternatively, you can edit the dependency in <Your Class>.cls-meta.xml, within the packageVersions tag.

 

Christian

All Answers

xnxn

Thanks.  This had me scratching my head.

xnxn

You get a confusing error message with VisualForce pages as well:

Exception: Dependent class is invalid and needs recompilation

 

Updating the version number in the .page-meta.xml file fixed the problem.

Daniel BallingerDaniel Ballinger

jlo wrote:

 

It turns out that in order to solve this problem, I needed to update the Version Settings for my PackageExtenderClass so that it referenced the 1.6 version of the 'myNamespace' Managed Package instead of the older 1.3 version.

 



Hi,

 

Can you please clarify how you updated the version settings for the apex class to reference a specific version of the managed package?

 

Thanks,

Daniel

xnxn

Daniel,

From Setup | Develop | Apex Classes | <Your Class> | [Edit], you can edit the dependency information on the Version Settings tab.  Alternatively, you can edit the dependency in <Your Class>.cls-meta.xml, within the packageVersions tag.

 

Christian

This was selected as the best answer
Daniel BallingerDaniel Ballinger

Thanks, I'd just found my way there through the help documents:

Click Version Settings to specify the version of Apex and the API used with this class. If your organization has installed managed packages from the AppExchange, you can also specify which version of each managed package to use with this class. Use the default values for all versions. This associates the class with the most recent version of Apex and the API, as well as each managed package. You can specify an older version of a managed package if you want to access components or functionality that differs from the most recent package version. You can specify an older version of Apex and the API to maintain specific behavior.

Also, the class that you are going to call in the managed package needs to be marked as global

The public access modifier declares that this class is visible in your application or namespace. The global access modifier declares that this class is known by all Apex code everywhere.
sahitya adminsahitya admin
hi
i have installed package in my org.now i wanted to access the class of managed package in my class.how can i call?thanks
RAVITEJA C 19RAVITEJA C 19
Hi 
Compile Error for contactpage.page: Apex class 'Contactpage1' does not exist at line None column None
What is the reason Iam Mentioning on apexclass same like as visualforcec page but it is not working can u please tell me

Visualforce page:

<apex:page controller="Contactpage1">
   <apex:form>
       <apex:pageBlock title="Contact Edit">
           <apex:pageBlockButtons location="both">
           <apex:commandButton action="{!Savecnct}"  value="Save Contact"/>

        </apex:pageBlockButtons>
        <apex:pageBlockSection title="Contact Information" collapsible="false">
        <apex:pageBlockSectionItem>
        <apex:outputLabel>
        First Name
      </apex:outputLabel> 
       <apex:inputField value="{!Contact.FirstName}">
      </apex:inputField>
     </apex:pageBlockSectionItem> 
      <apex:pageBlockSectionItem>
        <apex:outputLabel>
           Last Name

      </apex:outputLabel> 
       <apex:inputField value="{!Contact.LastName}">
      </apex:inputField>
     </apex:pageBlockSectionItem> 
      <apex:pageBlockSectionItem>
        <apex:outputLabel>
        Email
      </apex:outputLabel> 
       <apex:inputField value="{!Contact.Email}">
      </apex:inputField>
     </apex:pageBlockSectionItem> 
      <apex:pageBlockSectionItem>
        <apex:outputLabel>
     Department
      </apex:outputLabel> 
       <apex:inputField value="{!Contact.Department}">
      </apex:inputField>
     </apex:pageBlockSectionItem> 
      <apex:pageBlockSectionItem>
        <apex:outputLabel>
      Birthdate
      </apex:outputLabel> 
       <apex:inputField value="{!Contact.Birthdate}">
      </apex:inputField>
     </apex:pageBlockSectionItem> 
    </apex:pageBlockSection>
    <apex:pageBlockSection title="Address Information" collapsible="false">
    <apex:pageBlockSectionItem>
        <apex:outputLabel>
       Mailing Street    
      </apex:outputLabel> 
       <apex:inputField value="{!Contact.MailingStreet}">
      </apex:inputField>
     </apex:pageBlockSectionItem> 
     <apex:pageBlockSectionItem>
        <apex:outputLabel>
       Other Street
      </apex:outputLabel> 
       <apex:inputField value="{!Contact.OtherStreet}">
      </apex:inputField>
     </apex:pageBlockSectionItem> 
 </apex:pageBlockSection>
     
    </apex:pageBlock>
         
    </apex:form>
</apex:page>

Apex class:

public with sharing class Contactpage1 {

    public String cnctFirstName{set;get;}

    public Contactpage(){

    }
    public PageReference Savecnct();{

    Contact cnct = new Contact();

    cnct.FirstName = cnctFirstName;
    insert cnct;
    System.debug('cnct'+cnct);
        try{
            PageReference pgRef = new PageReference('/'+cnct.Id);

            return pgRef;
        }catch(Expection e){
            System.debug(e.getMessage());

        }
        return null;

}
}

       Thanks ,
      Ravi teja