mirror of
https://github.com/forcedotcom/afv-library.git
synced 2026-07-30 03:09:50 +08:00
102 lines
4.1 KiB
OpenEdge ABL
102 lines
4.1 KiB
OpenEdge ABL
/**
|
|
* Domain class for {SObject}.
|
|
* Encapsulates field-level defaults, derivations, and validations.
|
|
* Operates only on in-memory SObject data — no SOQL or DML.
|
|
*/
|
|
public with sharing class {SObject}Domain {
|
|
|
|
// ─── Constants ───────────────────────────────────────────────────────
|
|
// TODO: Add constants for default values, statuses, etc.
|
|
|
|
// ─── Field Defaults ──────────────────────────────────────────────────
|
|
|
|
/**
|
|
* Applies default field values to new {SObject} records.
|
|
* Call this before insert to ensure consistent defaults.
|
|
* @param records List of {SObject} records to apply defaults to
|
|
*/
|
|
public static void applyDefaults(List<{SObject}> records) {
|
|
if (records == null || records.isEmpty()) {
|
|
return;
|
|
}
|
|
|
|
for ({SObject} record : records) {
|
|
// TODO: Set default field values
|
|
// Example:
|
|
// if (record.Status__c == null) {
|
|
// record.Status__c = DEFAULT_STATUS;
|
|
// }
|
|
}
|
|
}
|
|
|
|
// ─── Derivations ────────────────────────────────────────────────────
|
|
|
|
/**
|
|
* Derives calculated field values based on other fields.
|
|
* Call this before insert and before update.
|
|
* @param records List of {SObject} records to derive values for
|
|
*/
|
|
public static void deriveFields(List<{SObject}> records) {
|
|
if (records == null || records.isEmpty()) {
|
|
return;
|
|
}
|
|
|
|
for ({SObject} record : records) {
|
|
// TODO: Derive calculated field values
|
|
// Example:
|
|
// record.FullAddress__c = buildFullAddress(record);
|
|
}
|
|
}
|
|
|
|
// ─── Validations ────────────────────────────────────────────────────
|
|
|
|
/**
|
|
* Validates {SObject} records and adds errors for any violations.
|
|
* Call this before insert and before update.
|
|
* @param records List of {SObject} records to validate
|
|
*/
|
|
public static void validate(List<{SObject}> records) {
|
|
if (records == null || records.isEmpty()) {
|
|
return;
|
|
}
|
|
|
|
for ({SObject} record : records) {
|
|
// TODO: Add validation rules
|
|
// Example:
|
|
// if (String.isBlank(record.Name)) {
|
|
// record.addError('Name is required.');
|
|
// }
|
|
}
|
|
}
|
|
|
|
// ─── Comparisons ────────────────────────────────────────────────────
|
|
|
|
/**
|
|
* Determines which fields have changed between old and new record versions.
|
|
* Useful in before update context.
|
|
* @param oldRecord The previous version of the record
|
|
* @param newRecord The current version of the record
|
|
* @return Set of field API names that have changed
|
|
*/
|
|
public static Set<String> getChangedFields({SObject} oldRecord, {SObject} newRecord) {
|
|
Set<String> changedFields = new Set<String>();
|
|
|
|
if (oldRecord == null || newRecord == null) {
|
|
return changedFields;
|
|
}
|
|
|
|
Map<String, Schema.SObjectField> fieldMap = Schema.SObjectType.{SObject}.fields.getMap();
|
|
for (String fieldName : fieldMap.keySet()) {
|
|
if (oldRecord.get(fieldName) != newRecord.get(fieldName)) {
|
|
changedFields.add(fieldName);
|
|
}
|
|
}
|
|
|
|
return changedFields;
|
|
}
|
|
|
|
// ─── Private Helpers ─────────────────────────────────────────────────
|
|
|
|
// TODO: Add private helper methods as needed
|
|
}
|