Skip to content

Commit 57ac1ea

Browse files
authored
Merge branch 'prerelease/develop-ga' into mvp_alpha
2 parents d34332d + 38d978d commit 57ac1ea

File tree

9 files changed

+86
-65
lines changed

9 files changed

+86
-65
lines changed

messages/assess.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"flexCardAssessmentCompleted": "FlexCard assessment completed",
6565
"globalAutoNumberAssessment": "GlobalAutoNumber Assessment",
6666
"assessedGlobalAutoNumbersCount": "Assessed %s GlobalAutoNumbers",
67-
"globalAutoNumberAssessmentCompleted": "GlobalAutoNumber assessment completed",
67+
"globalAutoNumberAssessmentCompleted": "The assessment for Global Auto Number is complete.",
6868
"omniScriptAssessment": "OmniScript and Integration Procedure Assessment",
6969
"assessedOmniScriptsCount": "Assessed %s OmniScripts",
7070
"assessedIntegrationProceduresCount": "Assessed %s Integration Procedures",

messages/migrate.json

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"migratingComponent": "Migrating: %s",
6767
"cleaningFailed": "Cleaning Failed: %s",
6868
"migrationCompleted": "Migration completed: %s",
69+
"migrationFailed": "Migration failed: %s",
6970
"formulaSyntaxError": "There was some problem while updating the formula syntax, please check the all the formula's syntax once : %s",
7071
"foundDataRaptorsToMigrate": "Found %s DataRaptors to migrate",
7172
"foundFlexCardsToMigrate": "Found %s FlexCards to migrate",
@@ -131,24 +132,26 @@
131132
"errorProcessingFlexiPage": "Error processing flexipage file: %s, %s",
132133
"flexipagesWithChanges": "Found %s flexipage files with changes",
133134
"omniGlobalAutoNumberPrefEnabled": "Successfully enabled OmniGlobalAutoNumberPref org preference",
134-
"errorEnablingOmniGlobalAutoNumberPref": "Error enabling OmniGlobalAutoNumberPref org preference",
135+
"errorEnablingOmniGlobalAutoNumberPref": "We couldn’t enable the Global Auto Number setting. Turn on the Global Auto Number setting manually, and try again. See <a href='https://help.salesforce.com/s/articleView?id=xcloud.os_standard_global_auto_number.htm&type=5' target='_blank'>Set Up Omni Global Auto Number</a>.",
135136
"performingPreMigrationChecks": "Performing pre-migration checks for Global Auto Number...",
136137
"preMigrationChecksPassed": "Pre-migration checks passed. Proceeding with Global Auto Number migration.",
137138
"preMigrationChecksFailed": "Pre-migration checks failed. Migration cannot proceed.",
138-
"globalAutoNumberPrefEnabledError": "Global Auto Number preference (OmniGlobalAutoNumberPref) is enabled. Please disable it before proceeding with migration.",
139-
"bothRollbackFlagsEnabledError": "Both RollbackIPChanges and RollbackDRChanges flags are enabled. Please disable both flags before proceeding with Global Auto Number migration.",
140-
"rollbackIPFlagEnabledError": "RollbackIPChanges flag is enabled. Please disable this flag before proceeding with Global Auto Number migration.",
141-
"rollbackDRFlagEnabledError": "RollbackDRChanges flag is enabled. Please disable this flag before proceeding with Global Auto Number migration.",
139+
"globalAutoNumberPrefEnabledError": "The Global Auto Number setting is enabled and global auto numbers have already been migrated.",
140+
"bothRollbackFlagsEnabledError": "We couldn’t turn on Global Auto Number. Disable the RollBackDRChanges and RollBackIPChanges <a href='https://help.salesforce.com/s/articleView?id=xcloud.os_standard_global_auto_number.htm&type=5' target='_blank'>Omni Interaction Configurations</a>, and try again.",
141+
"rollbackIPFlagEnabledError": "We couldn’t turn on Global Auto Number. Disable the RollBackIPChanges <a href='https://help.salesforce.com/s/articleView?id=xcloud.os_standard_global_auto_number.htm&type=5' target='_blank'>Omni Interaction Configurations</a> and try again.",
142+
"rollbackDRFlagEnabledError": "We couldn’t turn on Global Auto Number. Disable the RollBackDRChanges <a href='https://help.salesforce.com/s/articleView?id=xcloud.os_standard_global_auto_number.htm&type=5' target='_blank'>Omni Interaction Configurations</a> and try again.",
142143
"errorCheckingRollbackFlags": "Error checking rollback flags status.",
143144
"startingPostMigrationCleanup": "Starting post-migration cleanup for Global Auto Number...",
144145
"postMigrationCleanupCompleted": "Post-migration cleanup completed successfully.",
145-
"errorDuringPostMigrationCleanup": "Error during post-migration cleanup.",
146+
"errorDuringPostMigrationCleanup": "We’ve encountered an error during the post-migration cleanup. Try again later.",
146147
"globalAutoNumberNameChangeMessage": "Global Auto Number name has been modified to fit naming rules: %s",
147148
"duplicatedGlobalAutoNumberName": "Duplicated Global Auto Number name",
148149
"errorWhileUploadingGlobalAutoNumber": "An error occurred while uploading Global Auto Number: ",
149150
"startingGlobalAutoNumberAssessment": "Starting Global Auto Number assessment...",
150151
"foundGlobalAutoNumbersToAssess": "Found %s Global Auto Numbers to assess",
151152
"unexpectedError": "An unexpected error occurred during processing",
152-
"migrationValidationFailed": "Post Migration validation failed.",
153-
"incompleteMigrationDetected": "Incomplete migration detected. Source objects: %s, Target objects: %s."
154-
}
153+
"migrationValidationFailed": "The post-migration validation has failed.",
154+
"incompleteMigrationDetected": "We couldn’t complete the migration process",
155+
"errorCheckingGlobalAutoNumber": "We couldn’t check whether the Global Auto Number setting is enabled: %s. Try again later.",
156+
"errorMigrationMessage": "Error migrating object: %s"
157+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@salesforce/plugin-omnistudio-migration-tool",
33
"description": "This SFDX plugin migrates FlexCard, OmniScript, DataRaptor, and Integration Procedure custom objects to standard objects.",
4-
"version": "2.0.0-rc.3",
4+
"version": "2.0.0-rc.4",
55
"author": "Salesforce",
66
"bugs": "https://github.com/forcedotcom/cli/issues",
77
"dependencies": {

src/commands/omnistudio/migration/migrate.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ export default class Migrate extends OmniStudioBaseCommand {
174174
const debugTimer = DebugTimer.getInstance();
175175
// We need to truncate the standard objects first
176176
let objectMigrationResults = await this.truncateObjects(migrationObjects, debugTimer);
177+
objectMigrationResults = objectMigrationResults.filter(
178+
(result) => result.name !== Constants.GlobalAutoNumberComponentName
179+
);
177180
const allTruncateComplete = objectMigrationResults.length === 0;
178181

179182
if (allTruncateComplete) {
@@ -325,6 +328,7 @@ export default class Migrate extends OmniStudioBaseCommand {
325328
data: [],
326329
errors: [ex.message],
327330
});
331+
Logger.logVerbose(ex.stack);
328332
Logger.error(messages.getMessage('cleaningFailed', [cls.getName()]));
329333
}
330334
}
@@ -338,7 +342,11 @@ export default class Migrate extends OmniStudioBaseCommand {
338342
Logger.log(messages.getMessage('migratingComponent', [cls.getName()]));
339343
debugTimer.lap('Migrating: ' + cls.getName());
340344
const results = await cls.migrate();
341-
Logger.log(messages.getMessage('migrationCompleted', [cls.getName()]));
345+
if (results.some((result) => result?.errors?.length > 0)) {
346+
Logger.error(messages.getMessage('migrationFailed', [cls.getName()]));
347+
} else {
348+
Logger.log(messages.getMessage('migrationCompleted', [cls.getName()]));
349+
}
342350
objectMigrationResults = objectMigrationResults.concat(
343351
results.map((r) => {
344352
return {
@@ -353,11 +361,13 @@ export default class Migrate extends OmniStudioBaseCommand {
353361
Logger.error(ex.message);
354362
process.exit(1);
355363
}
356-
Logger.error('Error migrating object', ex);
364+
const errMsg = error instanceof Error ? error.message : String(error);
365+
Logger.error(messages.getMessage('errorMigrationMessage', [errMsg]));
366+
Logger.logVerbose(error);
357367
objectMigrationResults.push({
358368
name: cls.getName(),
359369
data: [],
360-
errors: [ex.message],
370+
errors: [errMsg],
361371
});
362372
}
363373
}

src/migration/globalautonumber.ts

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,23 @@ import { Logger } from '../utils/logger';
1313
import { createProgressBar } from './base';
1414
import { OrgPreferences } from '../utils/orgPreferences';
1515
import { OmniGlobalAutoNumberPrefManager } from '../utils/OmniGlobalAutoNumberPrefManager';
16+
import { Constants } from '../utils/constants/stringContants';
1617

1718
export class GlobalAutoNumberMigrationTool extends BaseMigrationTool implements MigrationTool {
1819
private prefManager: OmniGlobalAutoNumberPrefManager;
1920
private globalAutoNumberSettings: AnyJson[] | null = null;
2021

2122
constructor(namespace: string, connection: Connection, logger: Logger, messages: Messages, ux: UX) {
2223
super(namespace, connection, logger, messages, ux);
23-
this.prefManager = new OmniGlobalAutoNumberPrefManager(this.connection);
24+
this.prefManager = new OmniGlobalAutoNumberPrefManager(this.connection, this.messages);
2425
}
2526

2627
static readonly GLOBAL_AUTO_NUMBER_SETTING_NAME = 'GlobalAutoNumberSetting__c';
2728
static readonly OMNI_GLOBAL_AUTO_NUMBER_NAME = 'OmniGlobalAutoNumber';
2829
static readonly ROLLBACK_FLAGS: string[] = ['RollbackIPChanges', 'RollbackDRChanges'];
2930

3031
public getName(): string {
31-
return 'GlobalAutoNumber';
32+
return Constants.GlobalAutoNumberComponentName;
3233
}
3334

3435
public getRecordName(record: string) {
@@ -45,12 +46,11 @@ export class GlobalAutoNumberMigrationTool extends BaseMigrationTool implements
4546
}
4647

4748
public async truncate(): Promise<void> {
48-
try {
49-
// Perform pre-migration checks before truncation
50-
await this.performPreMigrationChecks();
49+
// Perform pre-migration checks before truncation
50+
await this.performPreMigrationChecks();
51+
this.globalAutoNumberSettings = await this.getAllGlobalAutoNumberSettings();
52+
if (this.globalAutoNumberSettings.length > 0) {
5153
await super.truncate(GlobalAutoNumberMigrationTool.OMNI_GLOBAL_AUTO_NUMBER_NAME);
52-
} catch (error) {
53-
Logger.error(this.messages.getMessage('cleaningFailed', [this.getName()]));
5454
}
5555
}
5656

@@ -62,7 +62,7 @@ export class GlobalAutoNumberMigrationTool extends BaseMigrationTool implements
6262
const migrationResult = await this.migrateGlobalAutoNumberData();
6363

6464
// Validate migration success
65-
const validationError = await this.validateMigrationSuccess(migrationResult.results);
65+
const validationError = await this.validateMigrationSuccess(migrationResult);
6666

6767
const errors = [];
6868
if (validationError) {
@@ -111,39 +111,41 @@ export class GlobalAutoNumberMigrationTool extends BaseMigrationTool implements
111111
return errorMessage;
112112
}
113113
} catch (error) {
114-
Logger.error(this.messages.getMessage('errorDuringPostMigrationCleanup'));
114+
Logger.logVerbose(error);
115+
const initialCount = this.globalAutoNumberSettings.length;
116+
const finalLength = (await this.getAllGlobalAutoNumberSettings()).length;
117+
const message =
118+
initialCount !== finalLength ? 'errorEnablingOmniGlobalAutoNumberPref' : 'errorDuringPostMigrationCleanup';
119+
const errorMessage = this.messages.getMessage(message);
120+
Logger.error(errorMessage);
121+
return errorMessage;
115122
}
116123
}
117124

118125
/**
119126
* Validate that all Global Auto Number objects are successfully migrated
120127
* before proceeding with source object truncation
121128
*/
122-
private async validateMigrationSuccess(uploadInfo: Map<string, UploadRecordResult>): Promise<string> {
129+
private async validateMigrationSuccess(migrationResults: MigrationResult): Promise<string> {
130+
const { results, records } = migrationResults;
123131
// Check if all uploaded records have success: true
124-
const failedRecords = Array.from(uploadInfo.values()).filter((result) => !result.success);
125-
const successfulRecords = Array.from(uploadInfo.values()).filter((result) => result.success);
132+
const failedRecords = Array.from(results.values()).filter((result) => !result.success);
133+
const successfulRecords = Array.from(results.values()).filter((result) => result.success);
126134

127135
// Get source count
128136
const sourceCount = this.globalAutoNumberSettings.length;
129137
const targetCount = successfulRecords.length;
130138

131139
// Check for count difference
132-
if (sourceCount !== targetCount) {
133-
const errorMessage = this.messages.getMessage('incompleteMigrationDetected', [sourceCount, targetCount]);
134-
Logger.error(errorMessage);
135-
Logger.error(this.messages.getMessage('migrationValidationFailed'));
136-
return errorMessage;
137-
}
138-
139-
// Check for failed records
140-
if (failedRecords.length > 0) {
141-
const failedCount = failedRecords.length;
142-
const totalCount = uploadInfo.size;
143-
const errorMessage = this.messages.getMessage('incompleteMigrationDetected', [
144-
totalCount,
145-
totalCount - failedCount,
146-
]);
140+
if (sourceCount !== targetCount || failedRecords.length > 0) {
141+
const uniqueErrors = [
142+
...new Set([...results.values(), ...records.values()].filter((r) => r?.errors?.length).map((r) => r.errors[0])),
143+
];
144+
let errorMessage = this.messages.getMessage('incompleteMigrationDetected');
145+
if (uniqueErrors.length > 0) {
146+
const errors = uniqueErrors.length === 1 ? uniqueErrors[0] : uniqueErrors.join(', ');
147+
errorMessage += ` because of ${errors}`;
148+
}
147149
Logger.error(errorMessage);
148150
Logger.error(this.messages.getMessage('migrationValidationFailed'));
149151
return errorMessage;
@@ -171,7 +173,6 @@ export class GlobalAutoNumberMigrationTool extends BaseMigrationTool implements
171173
const isEnabled = await this.prefManager.isEnabled();
172174
if (isEnabled) {
173175
const errorMessage = this.messages.getMessage('globalAutoNumberPrefEnabledError');
174-
Logger.error(errorMessage);
175176
throw new Error(errorMessage);
176177
}
177178
// Check rollback flags using existing utility
@@ -188,7 +189,6 @@ export class GlobalAutoNumberMigrationTool extends BaseMigrationTool implements
188189
} else if (enabledFlags.includes('RollbackDRChanges')) {
189190
errorMessage = this.messages.getMessage('rollbackDRFlagEnabledError');
190191
}
191-
Logger.error(errorMessage);
192192
throw new Error(errorMessage);
193193
}
194194
}
@@ -198,10 +198,6 @@ export class GlobalAutoNumberMigrationTool extends BaseMigrationTool implements
198198
let globalAutoNumberUploadInfo = new Map<string, UploadRecordResult>();
199199
const uniqueNames = new Set<string>();
200200

201-
// Query all GlobalAutoNumber settings
202-
DebugTimer.getInstance().lap('Query GlobalAutoNumber settings');
203-
this.globalAutoNumberSettings = await this.getAllGlobalAutoNumberSettings();
204-
205201
let progressCounter = 0;
206202
Logger.logVerbose(
207203
this.messages.getMessage('foundGlobalAutoNumbersToMigrate', [this.globalAutoNumberSettings.length])
@@ -262,16 +258,17 @@ export class GlobalAutoNumberMigrationTool extends BaseMigrationTool implements
262258
referenceId: recordId,
263259
hasErrors: true,
264260
success: false,
265-
errors: err,
261+
errors: [err],
266262
warnings: [],
267263
});
264+
Logger.logVerbose(err.stack);
268265
}
269266
}
270267

271268
progressBar.stop();
272269

273270
return {
274-
name: 'GlobalAutoNumber',
271+
name: Constants.GlobalAutoNumberComponentName,
275272
results: globalAutoNumberUploadInfo,
276273
records: originalGlobalAutoNumberRecords,
277274
errors: [],
@@ -288,6 +285,7 @@ export class GlobalAutoNumberMigrationTool extends BaseMigrationTool implements
288285
const globalAutoNumberAssessmentInfos = await this.processGlobalAutoNumberComponents(globalAutoNumbers);
289286
return globalAutoNumberAssessmentInfos;
290287
} catch (err) {
288+
Logger.logVerbose(err.stack);
291289
return [];
292290
}
293291
}
@@ -314,9 +312,8 @@ export class GlobalAutoNumberMigrationTool extends BaseMigrationTool implements
314312
warnings: [],
315313
errors: [this.messages.getMessage('unexpectedError')],
316314
});
317-
const error = e as Error;
318-
Logger.error(JSON.stringify(error));
319-
Logger.error(error.stack);
315+
Logger.error(e.message);
316+
Logger.logVerbose(e.stack);
320317
}
321318
progressBar.update(++progressCounter);
322319
}

src/utils/OmniGlobalAutoNumberPrefManager.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Connection } from '@salesforce/core';
1+
import { Connection, Messages } from '@salesforce/core';
22
import { MetadataInfo } from './interfaces';
33
import { Logger } from './logger';
44

@@ -12,9 +12,11 @@ import { Logger } from './logger';
1212
*/
1313
export class OmniGlobalAutoNumberPrefManager {
1414
private connection: Connection;
15+
private messages: Messages;
1516

16-
public constructor(connection: Connection) {
17+
public constructor(connection: Connection, messages: Messages) {
1718
this.connection = connection;
19+
this.messages = messages;
1820
}
1921

2022
/**
@@ -35,7 +37,7 @@ export class OmniGlobalAutoNumberPrefManager {
3537
return result?.enableOmniGlobalAutoNumberPref === 'true' || false;
3638
} catch (error) {
3739
const errMsg = error instanceof Error ? error.message : String(error);
38-
Logger.error(`Error checking OmniGlobalAutoNumberPref status: ${errMsg}`);
40+
Logger.error(this.messages.getMessage('errorCheckingGlobalAutoNumber', [errMsg]));
3941
return false;
4042
}
4143
}

src/utils/logger.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ export class Logger {
6464
Logger.sfUX.error(`\x1b[31m${message.message}\n${message.stack}\x1b[0m`);
6565
} else {
6666
if (error) {
67-
Logger.sfUX.error(`\x1b[31m${message}\n${error.message}\n${error.stack}\x1b[0m`);
68-
} else {
69-
Logger.sfUX.error(`\x1b[31m${message}\x1b[0m`);
67+
Logger.sfUX.error(`\x1b[31m${error.message}\n${error.stack}\x1b[0m`);
7068
}
7169
}
7270
}

test/migration/globalautonumber.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ describe('GlobalAutoNumberMigrationTool', () => {
251251
getMessageStub.withArgs('startingPostMigrationCleanup').returns('Starting cleanup...');
252252
getMessageStub.withArgs('omniGlobalAutoNumberPrefEnabled').returns('Preference enabled');
253253
getMessageStub.withArgs('postMigrationCleanupCompleted').returns('Cleanup completed');
254-
254+
await globalAutoNumberMigrationTool.truncate();
255255
// Act
256256
const result = await globalAutoNumberMigrationTool.migrate();
257257

@@ -342,7 +342,7 @@ describe('GlobalAutoNumberMigrationTool', () => {
342342
getMessageStub.withArgs('startingPostMigrationCleanup').returns('Starting cleanup...');
343343
getMessageStub.withArgs('incompleteMigrationDetected', [2, 1]).returns('Incomplete migration detected');
344344
getMessageStub.withArgs('migrationValidationFailed').returns('Migration validation failed');
345-
345+
await globalAutoNumberMigrationTool.truncate();
346346
// Act
347347
const result = await globalAutoNumberMigrationTool.migrate();
348348

@@ -385,7 +385,7 @@ describe('GlobalAutoNumberMigrationTool', () => {
385385
getMessageStub.withArgs('startingPostMigrationCleanup').returns('Starting cleanup...');
386386
getMessageStub.withArgs('incompleteMigrationDetected', [1, 0]).returns('Incomplete migration');
387387
getMessageStub.withArgs('migrationValidationFailed').returns('Migration validation failed');
388-
388+
await globalAutoNumberMigrationTool.truncate();
389389
// Act
390390
const result = await globalAutoNumberMigrationTool.migrate();
391391

0 commit comments

Comments
 (0)