Resolving “Unable to Find Apex Action Class” in Package Creation

Resolving “Unable to Find Apex Action Class” in Package Creation

On January 1, 2026, Posted by , In Salesforce Technical Questions, With Comments Off on Resolving “Unable to Find Apex Action Class” in Package Creation
Resolving "Unable to Find Apex Action Class" in Package Creation

Question

I am attempting to create a new version of my 2nd generation package after adding some custom fields using XML files. When I run the command to create the package version:

sf package version create --package "Foobar" -c --installation-key-bypass

I encounter the following error:

admin: Unable to find Apex action class referenced as 'AdminController'.

The AdminController class exists in previous versions of the package, along with all files that reference it. The new files I added do not interact with this class or any of the old files. I’ve successfully created beta versions of the package in the past few days. What could be causing this error? How can I debug it effectively?

Answer

Kickstart your Salesforce career with our hands-on Salesforce training in Bangalore. Gain real-world experience and job-ready skills—sign up for a free demo..!

Potential Cause: Apex Class Compilation Failure

One of the most common causes of this error is a compilation failure for the AdminController class. Salesforce essentially runs a deployment process when you create a package, and if the class fails to compile, Salesforce might not find the class during the package version creation process.

To debug this issue, follow these steps:

1. Deploy to a Scratch Org:

First, try deploying your package’s source code to a scratch org with the added changes to verify if the AdminController class compiles correctly. You can use the following command to deploy to a scratch org:

sf package version create --package "Foobar" -c --installation-key-bypass

2. Verify Class Compilation:

Once the deployment is complete, confirm that the AdminController class is compiling correctly by running a simple debug statement in the scratch org. You can use the following code snippet in your Apex code to verify the class is accessible and compiling:

System.debug(AdminController.someMethod());

3. Run Tests for the Class:

After confirming the class compiles, run the associated tests for AdminController to check if everything works as expected. Use the following command to run tests in the scratch org:

sf apex run test --target-org <scratch-org-alias> --result-format human

If the test fails, you may have to resolve any issues related to the class logic, dependencies, or syntax errors before proceeding.

Another Possible Cause: Namespace Conflicts

If your AdminController class belongs to a managed package or is referenced from another namespace, Salesforce might not recognize it if the correct namespace is not used.

To handle this, ensure that you’re using the appropriate namespace prefix. For example, if the class is from a package with the namespace namespacePrefix, modify your reference like so:

namespacePrefix.AdminController.someMethod();

This ensures that Salesforce can resolve the class correctly during the package version creation process.

Solution for Class Deletion or Re-adding

If you previously deleted and re-added the AdminController class, it could have introduced metadata inconsistencies. Deleting classes from packages is generally discouraged as it may lead to missing dependencies and other issues.

To avoid such issues, try the following:

  • Check for Orphaned References: Ensure that there are no leftover references or metadata related to the deleted class.
  • Recreate the Class: If necessary, recreate the class in the package with the correct references and metadata.

Additional Debugging Steps

If none of the above solutions work, consider the following steps:

1. Create a Fresh Scratch Org:

Try creating a fresh scratch org and deploy your entire package’s source code again. This ensures that the environment is clean and no previous issues affect the deployment.

sf org create scratch <org-name> --config <config-file>

2. Manual Metadata Verification:

Before running the sf package version create command again, manually verify that all relevant metadata is properly deployed and that the AdminController class is present and functional.

3. Check for Syntax Errors:

If the AdminController class is not compiling, double-check the code for syntax errors, missing imports, or incorrect annotations.

By following these steps, you should be able to identify the underlying issue causing the “unable to find class” error and resolve it effectively.

Master Salesforce with Expert Training in Bangalore

Our Salesforce training program is designed to provide personalized mentorship, thorough certification exam preparation, and expert interview coaching, ensuring you stand out in today’s competitive job market. With practical project experience, detailed study materials, and ongoing support, you’ll gain the confidence and skills necessary to succeed. By the end of the program, you’ll be well-prepared for certifications and equipped with the practical expertise that employers highly value. Begin your Salesforce journey with us and unlock rewarding career opportunities!

Our immersive Salesforce training in Bangalore equips you with the essential skills to thrive in the CRM industry. Covering Salesforce Admin, Developer, and AI domains, the program combines in-depth theory with hands-on, real-world applications. You’ll tackle complex business challenges through industry-relevant projects, gaining valuable practical experience.

Take the first step toward a successful Salesforce career—sign up for a FREE demo session today..!

Comments are closed.