Skip to content

Commit 1d9bee0

Browse files
authored
Merge pull request #366 from sf-kishore-kurri/u/kkurri/GA/W-18480479
feat: @W-18480479 : Enabling standard runtime along with data model
2 parents bd27796 + 3f6602b commit 1d9bee0

File tree

10 files changed

+550
-278
lines changed

10 files changed

+550
-278
lines changed

messages/assess.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,6 @@
142142
"relatedObjectsToProcess": "Objects to process are",
143143
"consentForExperienceSites": "By proceeding further, you hereby consent to enable digital experience metadata api(y/n). If y sites will be processed, if n expsites will not be processed",
144144
"failedToGetConsentError": "Failed to get user consent: %s",
145-
"settingDesignersToStandardModel": "Setting designers to use the standard data model",
146-
"errorSettingDesignersToStandardModel": "Error occurred while setting designers to use the standard data model",
147-
"designersSetToStandardModel": "Successfully executed setDesignersToUseStandardDataModel",
148-
"exceptionSettingDesignersToStandardModel": "Exception occurred while setting designers to use the standard data model",
149145
"noRelatedObjects": "No related objects to process",
150146
"turnOffExperienceBundleAPI": "Since ExperienceSiteMetadata API was programatically enabled, turing it off",
151147
"errorRevertingExperienceBundleMetadataAPI": "Exception occurred while reverting metadata API. Please do that manually",
@@ -177,7 +173,7 @@
177173
"flexcardStorageProcessingStarted": "Started preparing storage for flexcards",
178174
"errorWhileProcessingFlexcardStorage": "Error occurred while processing key for flexcard storage",
179175
"missingInfo": "Info is missing",
180-
"errorCheckingGlobalAutoNumber": "We couldnt check whether the Global Auto Number setting is enabled: %s. Try again later.",
176+
"errorCheckingGlobalAutoNumber": "We couldn't check whether the Global Auto Number setting is enabled: %s. Try again later.",
181177
"errorMigrationMessage": "Error migrating object: %s",
182178
"nameMappingUndefined": "Name Mapping is undefined",
183179
"experienceSiteException": "Exception occurred while processing experience sites",

messages/migrate.json

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@
111111
"errorParsingData": "Error while parsing data for template",
112112
"errorGeneratingHTML": "Error while generating HTML from template for %s with properties %s",
113113
"errorEvaluatingExpression": "Error evaluating expression: %s, %s",
114-
"manuallySwitchDesignerToStandardDataModel": "To complete the setup, please manually run the required Apex code to configure OmniStudio Designers to use the Standard Data Model <br> https://help.salesforce.com/s/articleView?id=xcloud.os_migrate_change_the_sobject_data_model_after_migration.htm&type=5",
115114
"labelStatusSkipped": "Skipped",
116115
"labelStatusFailed": "Failed",
117116
"labelStatusComplete": "Complete",
@@ -155,10 +154,6 @@
155154
"relatedObjectsToProcess": "Objects to process are",
156155
"consentForExperienceSites": "'By proceeding further, you hereby consent to enable digital experience metadata api(y/n). If y sites will be processed, if n expsites will not be processed';",
157156
"failedToGetConsentError": "Failed to get user consent: %s",
158-
"settingDesignersToStandardModel": "Setting designers to use the standard data model",
159-
"errorSettingDesignersToStandardModel": "Error occurred while setting designers to use the standard data model",
160-
"designersSetToStandardModel": "Successfully executed setDesignersToUseStandardDataModel",
161-
"exceptionSettingDesignersToStandardModel": "Exception occurred while setting designers to use the standard data model",
162157
"noRelatedObjects": "No related objects to process",
163158
"turnOffExperienceBundleAPI": "Since ExperienceSiteMetadata API was programatically enabled, turing it off",
164159
"errorRevertingExperienceBundleMetadataAPI": "Exception occurred while reverting metadata API. Please do that manually",
@@ -218,5 +213,22 @@
218213
"manifestDeployementStarted": "Manifest deployment started with id: %s",
219214
"migrationConsentMessage": "Make sure that all records listed in the Assessment Status column in the Assessment Report are marked as Green before proceeding with the migration. Do you want to proceed? Yes or No?",
220215
"truncationFailed": "Truncation failed for %s: %s",
221-
"invalidTypeMigrateErrorMessage": "We couldn't migrate your Omnistudio components in the %s namespace. Select the correct namespace and try again"
222-
}
216+
"invalidTypeMigrateErrorMessage": "We couldn't migrate your Omnistudio components in the %s namespace. Select the correct namespace and try again",
217+
"errorCheckingStandardRuntime": "We couldn't check whether the Standard OmniStudio Runtime setting is enabled: %s. Try again later.",
218+
"checkingStandardRuntimeStatus": "Checking Standard OmniStudio Runtime status...",
219+
"standardRuntimeAlreadyEnabled": "Standard OmniStudio Runtime is already enabled, no action needed.",
220+
"standardRuntimeEnabled": "Standard OmniStudio Runtime has been successfully enabled.",
221+
"errorEnablingStandardRuntime": "Failed to enable Standard OmniStudio Runtime: %s",
222+
"exceptionEnablingStandardRuntime": "Exception occurred while enabling Standard OmniStudio Runtime: %s",
223+
"manuallyEnableStandardRuntime": "Please manually enable the Standard OmniStudio Runtime setting in your org's OmniStudio Settings.",
224+
"standardDesignerAlreadyEnabled": "Standard OmniStudio designer is already enabled, no action needed for package: %s",
225+
"settingDesignersToStandardModel": "Setting OmniStudio designers to use standard data model",
226+
"designersSetToStandardModel": "OmniStudio designers have been successfully set to use standard data model.",
227+
"errorSettingDesignersToStandardModel": "Failed to set designers to standard data model: %s",
228+
"exceptionSettingDesignersToStandardModel": "Exception occurred while setting designers to standard data model: %s",
229+
"manuallySwitchDesignerToStandardDataModel": "Please manually switch the OmniStudio designer to use standard data model in your org. Follow the documentation <a href='https://help.salesforce.com/s/articleView?id=xcloud.os_migrate_change_the_sobject_data_model_after_migration.htm&type=5' target='_blank'>here</a>.",
230+
"checkingStandardDesignerStatus": "Checking if standard designer is already enabled for package: %s",
231+
"enableStandardRuntimeAfterDesigner": "Standard designer setup successful, proceeding with Standard Runtime enablement",
232+
"skipStandardRuntimeDueToFailure": "Skipping Standard Runtime enablement due to designer setup failure",
233+
"errorCheckingStandardDesigner": "Failed to check standard designer status for package %s: %s"
234+
}

src/commands/omnistudio/migration/migrate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export default class Migrate extends OmniStudioBaseCommand {
208208
);
209209

210210
if (!migrateOnly) {
211-
await postMigrate.setDesignersToUseStandardDataModel(namespace, actionItems);
211+
await postMigrate.executeTasks(namespace, actionItems);
212212
}
213213
// From here also actionItems need to be collected
214214
await postMigrate.restoreExperienceAPIMetadataSettings(
@@ -437,7 +437,7 @@ export default class Migrate extends OmniStudioBaseCommand {
437437
allVersions
438438
),
439439
new CardMigrationTool(namespace, conn, this.logger, messages, this.ux, allVersions),
440-
new GlobalAutoNumberMigrationTool(namespace, conn, this.logger, messages, this.ux),
440+
// new GlobalAutoNumberMigrationTool(namespace, conn, this.logger, messages, this.ux),
441441
];
442442
} else {
443443
// For single component migration, the order doesn't matter as much

src/migration/globalautonumber.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@ import { GlobalAutoNumberAssessmentInfo } from '../utils/interfaces';
1212
import { Logger } from '../utils/logger';
1313
import { createProgressBar } from './base';
1414
import { OrgPreferences } from '../utils/orgPreferences';
15-
import { OmniGlobalAutoNumberPrefManager } from '../utils/OmniGlobalAutoNumberPrefManager';
16-
15+
import { OmnistudioSettingsPrefManager } from '../utils/OmnistudioSettingsPrefManager';
1716
import { Constants } from '../utils/constants/stringContants';
1817

1918
export class GlobalAutoNumberMigrationTool extends BaseMigrationTool implements MigrationTool {
20-
private prefManager: OmniGlobalAutoNumberPrefManager;
19+
private prefManager: OmnistudioSettingsPrefManager;
2120
private globalAutoNumberSettings: AnyJson[] | null = null;
2221

2322
constructor(namespace: string, connection: Connection, logger: Logger, messages: Messages, ux: UX) {
2423
super(namespace, connection, logger, messages, ux);
25-
this.prefManager = new OmniGlobalAutoNumberPrefManager(this.connection, this.messages);
24+
this.prefManager = new OmnistudioSettingsPrefManager(this.connection, this.messages);
2625
}
2726

2827
static readonly GLOBAL_AUTO_NUMBER_SETTING_NAME = 'GlobalAutoNumberSetting__c';
@@ -101,7 +100,7 @@ export class GlobalAutoNumberMigrationTool extends BaseMigrationTool implements
101100
await super.truncate(this.namespacePrefix + GlobalAutoNumberMigrationTool.GLOBAL_AUTO_NUMBER_SETTING_NAME);
102101
Logger.logVerbose(this.messages.getMessage('postMigrationCleanupCompleted'));
103102
// Enable the org preference after successful cleanup
104-
const result = await this.prefManager.enable();
103+
const result = await this.prefManager.enableGlobalAutoNumber();
105104
if (result?.success) {
106105
Logger.logVerbose(this.messages.getMessage('omniGlobalAutoNumberPrefEnabled'));
107106
return '';
@@ -171,7 +170,7 @@ export class GlobalAutoNumberMigrationTool extends BaseMigrationTool implements
171170
*/
172171
private async performPreMigrationChecks(): Promise<void> {
173172
// Check if Global Auto Number preference is already enabled
174-
const isEnabled = await this.prefManager.isEnabled();
173+
const isEnabled = await this.prefManager.isGlobalAutoNumberEnabled();
175174
if (isEnabled) {
176175
const errorMessage = this.messages.getMessage('globalAutoNumberPrefEnabledError');
177176
throw new Error(errorMessage);

src/migration/postMigrate.ts

Lines changed: 98 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ExecuteAnonymousResult } from 'jsforce';
66
import { Logger } from '../utils/logger';
77
import { AnonymousApexRunner } from '../utils/apex/executor/AnonymousApexRunner';
88
import { Constants } from '../utils/constants/stringContants';
9+
import { OmnistudioSettingsPrefManager } from '../utils/OmnistudioSettingsPrefManager';
910
import { OrgPreferences } from '../utils/orgPreferences';
1011
import { BaseMigrationTool } from './base';
1112
import { Deployer } from './deployer';
@@ -17,6 +18,7 @@ export class PostMigrate extends BaseMigrationTool {
1718
private readonly relatedObjectsToProcess: string[];
1819
private readonly projectPath: string;
1920
private readonly deploymentConfig: { autoDeploy: boolean; authKey: string | undefined };
21+
private settingsPrefManager: OmnistudioSettingsPrefManager;
2022

2123
// Source Custom Object Names
2224
constructor(
@@ -35,32 +37,123 @@ export class PostMigrate extends BaseMigrationTool {
3537
this.relatedObjectsToProcess = relatedObjectsToProcess;
3638
this.deploymentConfig = deploymentConfig;
3739
this.projectPath = projectPath;
40+
this.settingsPrefManager = new OmnistudioSettingsPrefManager(connection, messages);
3841
}
3942

40-
public async setDesignersToUseStandardDataModel(
43+
/**
44+
* Execute post migration tasks with dependency handling.
45+
*/
46+
public async executeTasks(namespaceToModify: string, userActionMessage: string[]): Promise<string[]> {
47+
const designerOk = await this.enableDesignersToUseStandardDataModelIfNeeded(namespaceToModify, userActionMessage);
48+
if (designerOk) {
49+
await this.enableStandardRuntimeIfNeeded(userActionMessage);
50+
}
51+
return userActionMessage;
52+
}
53+
54+
/**
55+
* Checks if OmniStudio designers are already using the standard data model for the specific package.
56+
*/
57+
private async isStandardDesignerEnabled(namespaceToModify: string): Promise<boolean> {
58+
try {
59+
const query = `SELECT DeveloperName, Value FROM OmniInteractionConfig WHERE DeveloperName IN ('TheFirstInstalledOmniPackage', 'InstalledIndustryPackage')`;
60+
61+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
62+
const result = await this.connection.query(query);
63+
64+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
65+
if (result?.totalSize > 0) {
66+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
67+
const records = result.records as Array<{ DeveloperName: string; Value: string }>;
68+
69+
for (const record of records) {
70+
if (record.Value === namespaceToModify) {
71+
return true;
72+
}
73+
}
74+
return false;
75+
} else {
76+
return false;
77+
}
78+
} catch (error) {
79+
const errMsg = error instanceof Error ? error.message : String(error);
80+
Logger.error(this.messages.getMessage('errorCheckingStandardDesigner', [namespaceToModify, errMsg]));
81+
return false;
82+
}
83+
}
84+
85+
public async enableDesignersToUseStandardDataModelIfNeeded(
4186
namespaceToModify: string,
4287
userActionMessage: string[]
43-
): Promise<string[]> {
88+
): Promise<boolean> {
4489
try {
4590
Logger.logVerbose(this.messages.getMessage('settingDesignersToStandardModel'));
91+
92+
// First check if standard designer is already enabled for this package
93+
Logger.logVerbose(this.messages.getMessage('checkingStandardDesignerStatus', [namespaceToModify]));
94+
const isAlreadyEnabled = await this.isStandardDesignerEnabled(namespaceToModify);
95+
96+
if (isAlreadyEnabled) {
97+
Logger.logVerbose(this.messages.getMessage('standardDesignerAlreadyEnabled', [namespaceToModify]));
98+
return true;
99+
}
100+
46101
const apexCode = `
47102
${namespaceToModify}.OmniStudioPostInstallClass.useStandardDataModel();
48103
`;
49104

50105
const result: ExecuteAnonymousResult = await AnonymousApexRunner.run(this.org, apexCode);
51106

52107
if (result?.success === false) {
53-
const message = result?.exceptionStackTrace;
108+
const message = result?.exceptionStackTrace || result?.exceptionMessage || 'Unknown error';
109+
54110
Logger.error(this.messages.getMessage('errorSettingDesignersToStandardModel', [message]));
111+
Logger.logVerbose(this.messages.getMessage('skipStandardRuntimeDueToFailure'));
55112
userActionMessage.push(this.messages.getMessage('manuallySwitchDesignerToStandardDataModel'));
113+
114+
// Do NOT attempt to enable standard runtime when setup fails
115+
return false;
56116
} else if (result?.success === true) {
57117
Logger.logVerbose(this.messages.getMessage('designersSetToStandardModel'));
118+
return true;
119+
} else {
120+
// Handle unexpected result structure
121+
Logger.error('Received unexpected response from Apex execution - unable to determine success status');
122+
userActionMessage.push(this.messages.getMessage('manuallySwitchDesignerToStandardDataModel'));
123+
return false;
58124
}
59125
} catch (ex) {
60-
Logger.error(this.messages.getMessage('exceptionSettingDesignersToStandardModel', [JSON.stringify(ex)]));
126+
const errorDetails = ex instanceof Error ? ex.message : JSON.stringify(ex);
127+
Logger.error(this.messages.getMessage('exceptionSettingDesignersToStandardDataModel', [errorDetails]));
128+
Logger.logVerbose(this.messages.getMessage('skipStandardRuntimeDueToFailure'));
61129
userActionMessage.push(this.messages.getMessage('manuallySwitchDesignerToStandardDataModel'));
130+
return false;
131+
}
132+
}
133+
134+
/**
135+
* Enables Standard OmniStudio Runtime if it's currently disabled.
136+
*/
137+
private async enableStandardRuntimeIfNeeded(userActionMessage: string[]): Promise<void> {
138+
try {
139+
Logger.logVerbose(this.messages.getMessage('checkingStandardRuntimeStatus'));
140+
141+
const result = await this.settingsPrefManager.enableStandardRuntimeIfDisabled();
142+
143+
if (result === null) {
144+
Logger.logVerbose(this.messages.getMessage('standardRuntimeAlreadyEnabled'));
145+
} else if (result?.success === true) {
146+
Logger.logVerbose(this.messages.getMessage('standardRuntimeEnabled'));
147+
} else {
148+
const errors = result?.errors?.join(', ') || 'Unknown error';
149+
Logger.error(this.messages.getMessage('errorEnablingStandardRuntime', [errors]));
150+
userActionMessage.push(this.messages.getMessage('manuallyEnableStandardRuntime'));
151+
}
152+
} catch (error) {
153+
const errMsg = error instanceof Error ? error.message : String(error);
154+
Logger.error(this.messages.getMessage('exceptionEnablingStandardRuntime', [errMsg]));
155+
userActionMessage.push(this.messages.getMessage('manuallyEnableStandardRuntime'));
62156
}
63-
return userActionMessage;
64157
}
65158

66159
// If we processed exp sites and switched metadata api from off->on then only we revert it

src/utils/OmniGlobalAutoNumberPrefManager.ts

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)