1

I am trying to send an object(Account) as a parameter from my batch class, I am getting this exception.

FATAL_ERROR System.TypeException: Procedure is only valid for System.DmlException and System.MailException

Code:

Account InsertAcc = New Account();
InsertAcc.Name='Test';
Insert InsertAcc;
//My method calling
classname.methodname(InsertAcc);
//class be like:
 @AuraEnabled
 public static Responseclass methodname(Account Accobject){

}
6
  • Do you have any try catch in your Class method? Nov 29, 2019 at 11:24
  • yes I have but the same error is getting captured.
    – Jay
    Nov 29, 2019 at 12:03
  • Please add that part of your code as well in the question? Nov 29, 2019 at 12:04
  • where exactly exception thrown?
    – sdandamud1
    Nov 29, 2019 at 12:39
  • This is likely due to where you're sending the callout to this method from or the "context" it's sent in. Please post the code from your batch class and a bit more of the essence of your @AuraEnabled method.
    – crmprogdev
    Nov 29, 2019 at 13:23

1 Answer 1

1

The bug is likely in your Exception handling code.

The following message is indicating a method has been called on an instance of an Exception class that isn't applicable.

FATAL_ERROR System.TypeException: Procedure is only valid for System.DmlException and System.MailException

You need to be careful with exceptions because Apex will compile code that probably doesn't make sense for the Type. E.g. The following with produce the same error as you are getting:

try {
    Integer divideByZero = 1 / 0;
} catch (Exception e) {
     e.getDmlType(1);
}

The exception that gets thrown in this example is a MathException. The method getDmlType(i) isn't valid for it and apex will instead throw a TypeException if you aren't dealing with a DMLException or EmailException.

This can occur for the following methods:

  1. getDmlFieldNames(i)
  2. getDmlFields(i)
  3. getDmlId(i)
  4. getDmlIndex(i)
  5. getDmlMessage(i)
  6. getDmlStatusCode(i)
  7. getDmlType(i)
  8. getNumDml()

The line number of the TypeException should take you directly to the problem in the exception handling.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.