Skip to content

Commit 55318c2

Browse files
fix: updated error messages based on CX
1 parent 9269133 commit 55318c2

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

messages/migrate.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@
249249
"migrationSuccessfulMessage": "Migration process for org %s is complete and reports are ready for review in the folder %s",
250250
"metadataTablesAlreadyClean": "OmniStudio metadata tables are empty",
251251
"startingMetadataCleanup": "Initiated cleanup process for Omnistudio metadata tables.",
252-
"failedToCleanTables": "Table cleanup failed: %s",
252+
"failedToCleanTables": "Table cleanup failed: %s, Please contact Salesforce Support.",
253253
"errorCheckingMetadataTables": "Error checking Omnistudio metadata tables: %s",
254254
"metadataCleanupCompleted": "The Omnistudio metadata table cleanup process is complete. Total records cleaned: %s",
255255
"metadataCleanupConsentMessage": "By proceeding further, you hereby consent to clean up the Omnistudio metadata tables. Proceeding with the cleanup process will permanently delete all records from OmniUiCardConfig, OmniScriptConfig, OmniIntegrationProcConfig, and OmniDataTransformConfig tables. Do you want to proceed? [y/n]",
@@ -260,7 +260,7 @@
260260
"omniStudioSettingsMetadataEnabled": "The Omnistudio Metadata setting is enabled with standard data model.",
261261
"timeoutEnablingOmniStudioSettingsMetadata": "Timeout while checking the metadata enablement status. Tried for %s seconds.",
262262
"errorEnablingOmniStudioSettingsMetadata": "Error while enabling the Omnistudio Metadata setting: %s. Enable it manually.",
263-
"fieldIntegrityException": "Field integrity Exception while deleting metadata records from %s: %s",
263+
"fieldIntegrityExceptions": "Metadata cleanup failed for %s due to a field integrity exception. Deactivate Active %s and try again.",
264264
"manuallyEnableOmniStudioSettingsMetadata": "Manually enable the Omnistudio Metadata setting in your org’s Omnistudio Settings page.",
265265
"omniStudioMetadataEnableConsentNotGiven": "You’ve not consented to proceed with enabling the Omnistudio Metadata setting. We’ll not be able to proceed with the migration.",
266266
"enablingOmniStudioSettingsMetadataStatus": "Enabling Omnistudio Metadata setting…",

src/utils/config/OmniStudioMetadataCleanupService.ts

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ export class OmniStudioMetadataCleanupService {
2121
'OmniDataTransformConfig',
2222
];
2323

24+
private static readonly FIELD_MAP = {
25+
OmniUiCardConfig: 'Flexcard',
26+
OmniScriptConfig: 'OmniScript',
27+
OmniIntegrationProcConfig: 'Integration Procedure',
28+
OmniDataTransformConfig: 'Data Mapper',
29+
};
30+
2431
private readonly connection: Connection;
2532
private readonly messages: Messages;
2633

@@ -60,17 +67,33 @@ export class OmniStudioMetadataCleanupService {
6067

6168
let totalCleanedRecords = 0;
6269
const failedTables: string[] = [];
70+
const tablesWithFieldIntegrityExceptions: string[] = [];
71+
const toDeactivate: string[] = [];
6372

6473
for (const tableName of OmniStudioMetadataCleanupService.CONFIG_TABLES) {
65-
const recordCount = await this.cleanupOmniStudioMetadataTable(tableName);
74+
const result = await this.cleanupOmniStudioMetadataTable(tableName);
6675

67-
if (recordCount >= 0) {
68-
totalCleanedRecords += recordCount;
76+
if (result.recordCount >= 0) {
77+
totalCleanedRecords += result.recordCount;
6978
} else {
7079
failedTables.push(tableName);
80+
if (result.statusCode === 'FIELD_INTEGRITY_EXCEPTION') {
81+
tablesWithFieldIntegrityExceptions.push(tableName);
82+
toDeactivate.push(OmniStudioMetadataCleanupService.FIELD_MAP[tableName]);
83+
}
7184
}
7285
}
7386

87+
if (tablesWithFieldIntegrityExceptions.length > 0) {
88+
Logger.error(
89+
this.messages.getMessage('fieldIntegrityExceptions', [
90+
tablesWithFieldIntegrityExceptions.join(', '),
91+
toDeactivate.join(', '),
92+
])
93+
);
94+
return false;
95+
}
96+
7497
if (failedTables.length > 0) {
7598
Logger.error(this.messages.getMessage('failedToCleanTables', [failedTables.join(', ')]));
7699
return false;
@@ -88,20 +111,21 @@ export class OmniStudioMetadataCleanupService {
88111
* Checks a specific table for records and cleans them if found
89112
*
90113
* @param tableName - Name of the table to check and clean
91-
* @returns Promise<number> - number of cleaned records, or -1 if failed
114+
* @returns Promise<{recordCount: number, statusCode?: string}> - recordCount: number of cleaned records (or -1 if failed), statusCode: optional error status code
92115
*/
93-
private async cleanupOmniStudioMetadataTable(tableName: string): Promise<number> {
116+
private async cleanupOmniStudioMetadataTable(
117+
tableName: string
118+
): Promise<{ recordCount: number; statusCode?: string }> {
94119
const recordIds = await QueryTools.queryIds(this.connection, tableName);
95120

96121
if (recordIds.length === 0) {
97-
return 0;
122+
return { recordCount: 0 };
98123
}
99124

100125
const deleteResult = await NetUtils.deleteWithFieldIntegrityException(this.connection, recordIds);
101-
if (!deleteResult.success && deleteResult.statusCode === 'FIELD_INTEGRITY_EXCEPTION') {
102-
Logger.error(this.messages.getMessage('fieldIntegrityException', [tableName, deleteResult.message || '']));
103-
return -1;
126+
if (!deleteResult.success) {
127+
return { recordCount: -1, statusCode: deleteResult.statusCode };
104128
}
105-
return deleteResult.success ? recordIds.length : -1;
129+
return { recordCount: recordIds.length };
106130
}
107131
}

0 commit comments

Comments
 (0)