1

I started getting this error with new orgs I created for testing. my old orgs work with same code. FWIW, it is a 2GP managed package app. It works in development environments (before packaging it) and also in old orgs with installed version (managed release/beta) but when I tried to test in fresh orgs created for testing it shows this error.

I debug it and got following exception : System.TypeException: myapp_namesapce.PaymentAccountAndSiteRequestItem does not have a no-arg constructor But that class do have no-argument constructor.

public class PaymentAccountAndSiteRequestItem {
  @AuraEnabled
  public string SFCurrentBaseUrl { get; set; }
  @AuraEnabled
  public string PaymentAccountId { get; set; }
  public PaymentAccountAndSiteRequestItem() {
  }
}

This is the method where it fails. This method is called from a LWC component (part of same 2gp package)

public with sharing class CheckoutPaymentController {
@AuraEnabled
  public static PaymentAccountWithSiteInfo getPaymentAccountAndSiteInfoDetail(
    PaymentAccountAndSiteRequestItem paymentAccountAndSiteRequestItemInstance
  ) {
}
}

And here's the response classes

global class PaymentAccountAuraDTO {
    @AuraEnabled
    public String Name { get; set; }
    @AuraEnabled
    public string RecordId { get; set; }
    @AuraEnabled
    public string PublishableKey { get; set; }

    public PaymentAccountAuraDTO() {
      this.Name = '';
      this.RecordId = '';
      this.PublishableKey = '';
    }
  }
public with sharing class CheckoutPaymentController {
public class PaymentAccountWithSiteInfo {
    @AuraEnabled
    public string SFUrlForStripeCallback { get; set; }
    @AuraEnabled
    public PaymentAccountDTOProvider.PaymentAccountAuraDTO PaymentAccountAuraDTOInfo { get; set; }
    public PaymentAccountWithSiteInfo() {
    }
  }
}
16
  • Please edit your post to show the code that causes the exception, and clarify if the two classes are or are not in the same package.
    – David Reed
    Oct 31, 2022 at 3:48
  • 2
    Salesforce has started locking down constructors by scope in various places, with Lightning Components covered in the release notes.
    – Phil W
    Oct 31, 2022 at 7:20
  • Per salesforce internal logs, the stack trace Id (-1279386781) points to Error trying to serialize action response.No content to map to Object due to end of input Oct 31, 2022 at 10:11
  • @DavidReed updated with code where it fails Oct 31, 2022 at 18:39
  • 1
    Please include text, not screenshots. Screenshots aren't accessible to users who use assistive technologies and make it harder for everyone to copy/paste and analyze the code.
    – David Reed
    Oct 31, 2022 at 18:55

2 Answers 2

1

You should contact Salesforce support. This is a definitely case when something has broken on SF internal implementation.

Update:

It is Release Update https://login.salesforce.com/ui/setup/releaseUpdate/ReleaseUpdatePage?action=detail&devName=AuraApexActionParamCtrAccessCheckRU that is breaking this.

https://help.salesforce.com/s/articleView?id=release-notes.rn_lc_block_public_constructor_package.htm&type=5&release=240

It describes a case where subscribers try to access the constructors from the package, however, it breaks the packaged lwc communication to packaged apex.

As a workaround, you might consider using Map with internal conversion to the object you had before

public with sharing class CheckoutPaymentController {
    @AuraEnabled
    public static PaymentAccountWithSiteInfo 
        getPaymentAccountAndSiteInfoDetail(
            Map<String, Object> paymentAccountAndSiteRequestItemInstance) {
       PaymentAccountAndSiteRequestItem item = (PaymentAccountAndSiteRequestItem) JSON.deserialize(JSON.serialize(paymentAccountAndSiteRequestItemInstance), PaymentAccountAndSiteRequestItem.class()); 
 
    }

}

We are going to try the similar workaround for our client.


Some updates.

On January 2nd 2023 Salesforce support reported that they are going to change the internal salesforce error into Cannot instantiate an apex class with non global constructor.

They suggested to add a global constructor to public class, which is not an option for us, since we don't want to expose DTO to subscribers.

Another suggested option is to add @namespaceAccessible annotation to the public constructor which actually works, but I don't understand why, since per documentation

The @namespaceAccessible makes public Apex in a package available to other packages that use the same namespace

Since it only makes a public apex method or property available to other packages, it makes no sense how it can help in the case when there is a single package and no other packages.


Another update

As of January 12th 17:21 UTC/GMT, I can no longer reproduce the original issue on preview orgs (Spring 2023). Looks like @namespaceAccessible apex annotation is no longer needed.


Another update

As of January 20th 11:05 UTC/GMT, I can no longer reproduce the original issue on both preview and non-preview orgs.

I have received the following information from the Salesforce support.

  1. Firstly they implemented a change to error message in Salesforce patch release 240.16 from An internal server error has occurred Error ID: 795864710-26263 (-1279386781) into Cannot instantiate an apex class with non global constructor
  2. The actual bug was resolved in Salesforce patch release 240.19 because many customers have complained about it.
0

I cannnot comment because i don't have enough reputation, but can you try to leave the param object 'PaymentAccountAndSiteRequestItem' to use a map instead? I know it is not a perfect solution but the map will probably work.

We have also had some issues with the objects as params, sometimes even the same implementation as a working previously created implementation.

public with sharing class CheckoutPaymentController {
    @AuraEnabled
    public static PaymentAccountWithSiteInfo 
        getPaymentAccountAndSiteInfoDetail(
            Map<String, String> paymentAccountAndSiteRequestItemInstance) {}
}
2
  • Hey @Dieter, thanks. Yeah that could be a workaround if this doesn't work. But I have this structure in other places as well and that would need more code refactoring. It was working before winter 23 orgs so It should work it is very basic structure to pass information around. I must be missing something or probably a sf bug in new release. Nov 7, 2022 at 12:04
  • Yes i agree, i must say that we currently do not have this issue. One other option you may have is JSON encode and decode on the first line in the function (that is something you will find a lot on Salesforce forums). If you really want to fix this issue you can log it in a case with the error id. But that will take time and meetings probably. Nov 8, 2022 at 13:05

You must log in to answer this question.

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