User may set the Class Field to mandatory by ticking the Make Classes Mandatory field on Setup > Accounting > Accounting Preferences > General tab. This can also be done via SuiteScript.
var accountingPref = config.load({
type: config.Type.ACCOUNTING_PREFERENCES
});
accountingPref.setValue({
fieldId: ‘CLASSMANDATORY’,
value: true
});
accountingPref.save();