Skip to content

Commit ce32602

Browse files
authored
Allow to use another org to call Agentforce (#1231)
* Allow to use another org to call Agentforce * [Mega-Linter] Apply linters fixes :) --------- Co-authored-by: nvuillam <17500430+nvuillam@users.noreply.github.com>
1 parent e55b5d9 commit ce32602

37 files changed

+134
-33
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
Note: Can be used with `sfdx plugins:install sfdx-hardis@beta` and docker image `hardisgroupcom/sfdx-hardis@beta`
66

7+
- Allow to use another org to call Agentforce, by previously connecting to an org alias TECHNICAL_ORG (to do that, just define SFDX_AUTH_URL_TECHNICAL_ORG and [hardis:auth:login](https://sfdx-hardis.cloudity.com/hardis/auth/login/) will handle the rest)
8+
79
## [5.35.0] 2025-05-18
810

911
- [hardis:doc:project2markdown](https://sfdx-hardis.cloudity.com/hardis/doc/project2markdown/) new features and fixes:

defaults/ci/.github/workflows/check-deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ jobs:
5959
SFDX_CLIENT_KEY_PREPROD: ${{ secrets.SFDX_CLIENT_KEY_PREPROD}}
6060
SFDX_CLIENT_ID_MAIN: ${{ secrets.SFDX_CLIENT_ID_MAIN}}
6161
SFDX_CLIENT_KEY_MAIN: ${{ secrets.SFDX_CLIENT_KEY_MAIN}}
62+
SFDX_AUTH_URL_TECHNICAL_ORG: ${{ SFDX_AUTH_URL_TECHNICAL_ORG }}
6263
SFDX_DEPLOY_WAIT_MINUTES: 120 # Override if necessary
6364
SFDX_TEST_WAIT_MINUTES: 120 # Override if necessary
6465
CI_COMMIT_REF_NAME: ${{ github.event.pull_request.base.ref }} # Defines the target branch of the PR

defaults/ci/.github/workflows/process-deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ jobs:
5858
SFDX_CLIENT_KEY_PREPROD: ${{ secrets.SFDX_CLIENT_KEY_PREPROD}}
5959
SFDX_CLIENT_ID_MAIN: ${{ secrets.SFDX_CLIENT_ID_MAIN}}
6060
SFDX_CLIENT_KEY_MAIN: ${{ secrets.SFDX_CLIENT_KEY_MAIN}}
61+
SFDX_AUTH_URL_TECHNICAL_ORG: ${{ secrets.SFDX_AUTH_URL_TECHNICAL_ORG }}
6162
SFDX_DEPLOY_WAIT_MINUTES: 120 # Override if necessary
6263
SFDX_TEST_WAIT_MINUTES: 120 # Override if necessary
6364
CI_COMMIT_REF_NAME: ${{ env.BRANCH }} # Defines the target branch of the PR

defaults/ci/Jenkinsfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pipeline {
1515
SFDX_CLIENT_KEY_PREPROD = credentials('SFDX_CLIENT_KEY_PREPROD') //Example
1616
SFDX_CLIENT_ID_MAIN = credentials('SFDX_CLIENT_ID_MAIN') //Example
1717
SFDX_CLIENT_KEY_MAIN = credentials('SFDX_CLIENT_KEY_MAIN') //Example
18+
SFDX_AUTH_URL_TECHNICAL_ORG = credentials('SFDX_AUTH_URL_TECHNICAL_ORG')
1819
SLACK_TOKEN = credentials('SLACK_TOKEN') // Remove if not used
1920
SLACK_CHANNEL_ID = credentials('SLACK_CHANNEL_ID') // Remove if not used
2021
NOTIF_EMAIL_ADDRESS = credentials('NOTIF_EMAIL_ADDRESS') // Remove if not used

defaults/ci/azure-pipelines-checks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ jobs:
8383
JIRA_PAT: $(JIRA_HOST)
8484
JIRA_TICKET_REGEX: $(JIRA_TICKET_REGEX)
8585
OPENAI_API_KEY: $(OPENAI_API_KEY)
86+
SFDX_AUTH_URL_TECHNICAL_ORG: $(SFDX_AUTH_URL_TECHNICAL_ORG)
8687
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
8788
CI_SFDX_HARDIS_AZURE_TOKEN: $(System.AccessToken)
8889
SYSTEM_COLLECTIONURI: $(System.CollectionUri)

defaults/ci/azure-pipelines-deployment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ jobs:
7777
JIRA_PAT: $(JIRA_HOST)
7878
JIRA_TICKET_REGEX: $(JIRA_TICKET_REGEX)
7979
SFDX_DEPLOY_WAIT_MINUTES: 150
80+
SFDX_AUTH_URL_TECHNICAL_ORG: $(SFDX_AUTH_URL_TECHNICAL_ORG)
8081
CI: "true"
8182
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
8283
CI_SFDX_HARDIS_AZURE_TOKEN: $(System.AccessToken)

docs/salesforce-ai-setup.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ See the [list of prompts used by sfdx-hardis](salesforce-ai-prompts.md) , and ho
4242
- A prompt template **SfdxHardisGenericPrompt** (type `Flex`) must exist in the default org, with input variable **PromptText** (type `FreeText`)
4343
- The connected used must be assigned to permission set **Prompt Template User**
4444

45-
| Variable | Description | Default |
46-
|------------------------------------|-------------------------------------------------------|----------------------------------------------------------------------------------------------------------------|
47-
| USE_AGENTFORCE | Set to true to activate the use of Agentforce prompts | false |
48-
| GENERIC_AGENTFORCE_PROMPT_TEMPLATE | Set this variable to override default prompt template | `SfdxHardisGenericPrompt` |
49-
| GENERIC_AGENTFORCE_PROMPT_URL | Set this variable to override default prompt url | `/services/data/v{{API_VERSION}}/einstein/prompt-templates/{{GENERIC_AGENTFORCE_PROMPT_TEMPLATE}}/generations` |
45+
| Variable | Description | Default |
46+
|------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------|
47+
| USE_AGENTFORCE | Set to true to activate the use of Agentforce prompts | false |
48+
| GENERIC_AGENTFORCE_PROMPT_TEMPLATE | Set this variable to override default prompt template | `SfdxHardisGenericPrompt` |
49+
| GENERIC_AGENTFORCE_PROMPT_URL | Set this variable to override default prompt url | `/services/data/v{{API_VERSION}}/einstein/prompt-templates/{{GENERIC_AGENTFORCE_PROMPT_TEMPLATE}}/generations` |
50+
| SFDX_AUTH_URL_TECHNICAL_ORG | If you want to use another org to call Agentforce (like a [Developer Org](https://developer.salesforce.com/signup) just to test the feature), you can define this variable (get Auth Url using `sf org display --verbose --json`) | <!-- --> |
5051

5152
![](assets/images//screenshot-agentforce-config-1.jpg)
5253

src/commands/hardis/auth/login.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,27 @@
22
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
33
import { Messages } from '@salesforce/core';
44
import { AnyJson } from '@salesforce/ts-types';
5+
import { authOrg } from '../../../common/utils/authUtils.js';
6+
import { CONSTANTS, getEnvVar } from '../../../config/index.js';
57

68
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
79
const messages = Messages.loadMessages('sfdx-hardis', 'org');
810

911
export default class Login extends SfCommand<any> {
1012
public static title = 'Login';
1113

12-
public static description = messages.getMessage('loginToOrg');
14+
public static description = `
15+
Logins to a Salesforce org from CI/CD workflows.
16+
17+
Will use the variables and files defined by configuration commands:
18+
19+
- CI/CD repos: [Configure Org CI Authentication](${CONSTANTS.DOC_URL_ROOT}/hardis/project/configure/auth/)
20+
- Monitoring repos: [Configure Org Monitoring](${CONSTANTS.DOC_URL_ROOT}/hardis/org/configure/monitoring/)
21+
22+
If you have a technical org (for example to call Agentforce from another org, you can define variable SFDX_AUTH_URL_TECHNICAL_ORG and it will authenticate it with alias TECHNICAL_ORG)
23+
24+
You can get SFDX_AUTH_URL_TECHNICAL_ORG value by running the command: \`sf org display --verbose --json\` and copy the value of the field \`sfdxAuthUrl\` in the output.
25+
`;
1326

1427
public static examples = [
1528
'$ sf hardis:auth:login',
@@ -63,6 +76,17 @@ export default class Login extends SfCommand<any> {
6376
scratch,
6477
});
6578

79+
// Login to secondary org
80+
if (getEnvVar('TECHNICAL_ORG_ALIAS') || getEnvVar('SFDX_AUTH_URL_TECHNICAL_ORG')) {
81+
await authOrg('TECHNICAL_ORG', {
82+
checkAuth: true,
83+
Command: this,
84+
devHub: false,
85+
scratch: false,
86+
argv: this.argv
87+
});
88+
}
89+
6690
// Return an object to be displayed with --json
6791
return { outputString: 'Logged to Salesforce org' };
6892
}

src/commands/hardis/doc/flow2markdown.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { isCI, uxLog } from '../../../common/utils/index.js';
1010
import { MetadataUtils } from '../../../common/metadata-utils/index.js';
1111
import { generateFlowMarkdownFile, generateHistoryDiffMarkdown, generateMarkdownFileWithMermaid } from '../../../common/utils/mermaidUtils.js';
1212
import { CONSTANTS } from '../../../config/index.js';
13+
import { setConnectionVariables } from '../../../common/utils/orgUtils.js';
1314

1415
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
1516
const messages = Messages.loadMessages('sfdx-hardis', 'org');
@@ -80,7 +81,7 @@ If [AI integration](${CONSTANTS.DOC_URL_ROOT}/salesforce-ai-setup/) is configure
8081
this.withPdf = flags.pdf === true ? true : false;
8182
this.singleFileMode = this.inputFiles != null && this.inputFiles.length == 1;
8283
this.debugMode = flags.debug || false;
83-
globalThis.jsForceConn = flags['target-org']?.getConnection(); // Required for some notifications providers like Email, or for Agentforce
84+
await setConnectionVariables(flags['target-org']?.getConnection(), true); // Required for some notifications providers like Email, or for Agentforce
8485

8586

8687
if (this.inputFiles === null && !isCI) {

src/commands/hardis/doc/project2markdown.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { DocBuilderLwc } from '../../../common/docBuilder/docBuilderLwc.js';
3737
import { DocBuilderAutoResponseRules } from "../../../common/docBuilder/docBuilderAutoResponseRules.js";
3838
import { DocBuilderEscalationRules } from '../../../common/docBuilder/docBuilderEscalationRules.js';
3939
import { DocBuilderPackage } from '../../../common/docBuilder/docBuilderPackage.js';
40+
import { setConnectionVariables } from '../../../common/utils/orgUtils.js';
4041

4142
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
4243
const messages = Messages.loadMessages('sfdx-hardis', 'org');
@@ -194,7 +195,7 @@ ${this.htmlInstructions}
194195
this.withHistory = flags["with-history"] === true ? true : false;
195196
this.withPdf = flags.pdf === true ? true : false;
196197
this.debugMode = flags.debug || false;
197-
globalThis.jsForceConn = flags['target-org']?.getConnection(); // Required for some notifications providers like Email, or for Agentforce
198+
await setConnectionVariables(flags['target-org']?.getConnection(), true);// Required for some notifications providers like Email, or for Agentforce
198199

199200
await fs.ensureDir(this.outputMarkdownRoot);
200201
const currentBranch = await getCurrentGitBranch()

src/commands/hardis/lint/access.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { Parser } from 'xml2js';
2323
import { CONSTANTS, getConfig } from '../../../config/index.js';
2424
import { getBranchMarkdown, getNotificationButtons, getSeverityIcon } from '../../../common/utils/notifUtils.js';
2525
import { GLOB_IGNORE_PATTERNS } from '../../../common/utils/projectUtils.js';
26+
import { setConnectionVariables } from '../../../common/utils/orgUtils.js';
2627

2728
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
2829
const messages = Messages.loadMessages('sfdx-hardis', 'org');
@@ -486,7 +487,7 @@ This command is part of [sfdx-hardis Monitoring](${CONSTANTS.DOC_URL_ROOT}/sales
486487
attachments = [{ text: notifDetailText }];
487488
}
488489

489-
globalThis.jsForceConn = flags['target-org']?.getConnection(); // Required for some notifications providers like Email
490+
await setConnectionVariables(flags['target-org']?.getConnection());// Required for some notifications providers like Email
490491
await NotifProvider.postNotifications({
491492
type: 'LINT_ACCESS',
492493
text: notifText,

src/commands/hardis/lint/metadatastatus.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { getBranchMarkdown, getNotificationButtons, getSeverityIcon } from '../.
1717
import { generateCsvFile, generateReportPath } from '../../../common/utils/filesUtils.js';
1818
import { GLOB_IGNORE_PATTERNS } from '../../../common/utils/projectUtils.js';
1919
import { CONSTANTS } from '../../../config/index.js';
20+
import { setConnectionVariables } from '../../../common/utils/orgUtils.js';
2021

2122
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
2223
const messages = Messages.loadMessages('sfdx-hardis', 'org');
@@ -157,7 +158,7 @@ This command is part of [sfdx-hardis Monitoring](${CONSTANTS.DOC_URL_ROOT}/sales
157158
uxLog(this, 'No draft flow or validation rule files detected.');
158159
}
159160
// Post notifications
160-
globalThis.jsForceConn = flags['target-org']?.getConnection(); // Required for some notifications providers like Email
161+
await setConnectionVariables(flags['target-org']?.getConnection());// Required for some notifications providers like Email
161162
await NotifProvider.postNotifications({
162163
type: 'METADATA_STATUS',
163164
text: notifText,

src/commands/hardis/lint/missingattributes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { MessageAttachment } from '@slack/types';
1717
import { getBranchMarkdown, getNotificationButtons, getSeverityIcon } from '../../../common/utils/notifUtils.js';
1818
import { generateCsvFile, generateReportPath } from '../../../common/utils/filesUtils.js';
1919
import { GLOB_IGNORE_PATTERNS } from '../../../common/utils/projectUtils.js';
20+
import { setConnectionVariables } from '../../../common/utils/orgUtils.js';
2021

2122
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
2223
const messages = Messages.loadMessages('sfdx-hardis', 'org');
@@ -80,7 +81,7 @@ export default class MetadataStatus extends SfCommand<any> {
8081
uxLog(this, 'No missing descriptions on fields have been found');
8182
}
8283
// Post notifications
83-
globalThis.jsForceConn = flags['target-org']?.getConnection(); // Required for some notifications providers like Email
84+
await setConnectionVariables(flags['target-org']?.getConnection());// Required for some notifications providers like Email
8485
await NotifProvider.postNotifications({
8586
type: 'MISSING_ATTRIBUTES',
8687
text: notifText,

src/commands/hardis/lint/unusedmetadatas.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { generateCsvFile, generateReportPath } from '../../../common/utils/files
1818
import { uxLog } from '../../../common/utils/index.js';
1919
import { GLOB_IGNORE_PATTERNS } from '../../../common/utils/projectUtils.js';
2020
import { CONSTANTS } from '../../../config/index.js';
21+
import { setConnectionVariables } from '../../../common/utils/orgUtils.js';
2122

2223
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
2324
const messages = Messages.loadMessages('sfdx-hardis', 'org');
@@ -94,7 +95,7 @@ This command is part of [sfdx-hardis Monitoring](${CONSTANTS.DOC_URL_ROOT}/sales
9495
uxLog(this, 'No unused labels or custom permissions detected.');
9596
}
9697
// Post notification
97-
globalThis.jsForceConn = flags['target-org']?.getConnection(); // Required for some notifications providers like Email
98+
await setConnectionVariables(flags['target-org']?.getConnection());// Required for some notifications providers like Email
9899
await NotifProvider.postNotifications({
99100
type: 'UNUSED_METADATAS',
100101
text: notifText,

src/commands/hardis/org/diagnose/audittrail.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { NotifProvider, NotifSeverity } from '../../../../common/notifProvider/i
1111
import { prompts } from '../../../../common/utils/prompts.js';
1212
import { generateCsvFile, generateReportPath } from '../../../../common/utils/filesUtils.js';
1313
import { getNotificationButtons, getOrgMarkdown, getSeverityIcon } from '../../../../common/utils/notifUtils.js';
14+
import { setConnectionVariables } from '../../../../common/utils/orgUtils.js';
1415

1516
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
1617
const messages = Messages.loadMessages('sfdx-hardis', 'org');
@@ -283,7 +284,7 @@ This command is part of [sfdx-hardis Monitoring](${CONSTANTS.DOC_URL_ROOT}/sales
283284
notifAttachments = [{ text: notifDetailText }];
284285
}
285286

286-
globalThis.jsForceConn = flags['target-org']?.getConnection(); // Required for some notifications providers like Email
287+
await setConnectionVariables(flags['target-org']?.getConnection());// Required for some notifications providers like Email
287288
await NotifProvider.postNotifications({
288289
type: 'AUDIT_TRAIL',
289290
text: notifText,

src/commands/hardis/org/diagnose/instanceupgrade.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { uxLog } from '../../../../common/utils/index.js';
99
import { soqlQuery } from '../../../../common/utils/apiUtils.js';
1010
import { NotifProvider, NotifSeverity } from '../../../../common/notifProvider/index.js';
1111
import { getNotificationButtons, getOrgMarkdown } from '../../../../common/utils/notifUtils.js';
12+
import { setConnectionVariables } from '../../../../common/utils/orgUtils.js';
1213

1314
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
1415
const messages = Messages.loadMessages('sfdx-hardis', 'org');
@@ -92,7 +93,7 @@ export default class DiagnoseInstanceUpgrade extends SfCommand<any> {
9293
uxLog(this, c.green(notifText));
9394
}
9495

95-
globalThis.jsForceConn = flags['target-org']?.getConnection(); // Required for some notifications providers like Email
96+
await setConnectionVariables(flags['target-org']?.getConnection());// Required for some notifications providers like Email
9697
await NotifProvider.postNotifications({
9798
type: 'ORG_INFO',
9899
text: notifText,

src/commands/hardis/org/diagnose/legacyapi.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { NotifProvider, NotifSeverity } from '../../../../common/notifProvider/i
1616
import { generateCsvFile, generateReportPath } from '../../../../common/utils/filesUtils.js';
1717
import { CONSTANTS } from '../../../../config/index.js';
1818
import { FileDownloader } from '../../../../common/utils/fileDownloader.js';
19+
import { setConnectionVariables } from '../../../../common/utils/orgUtils.js';
1920
const dnsPromises = dns.promises;
2021

2122
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
@@ -241,7 +242,7 @@ See article to solve issue before it's too late:
241242
notifText = `${this.allErrors.length} deprecated Salesforce API versions are used in ${orgMarkdown}`;
242243
}
243244
// Post notifications
244-
globalThis.jsForceConn = flags['target-org']?.getConnection(); // Required for some notifications providers like Email
245+
await setConnectionVariables(flags['target-org']?.getConnection());// Required for some notifications providers like Email
245246
await NotifProvider.postNotifications({
246247
type: 'LEGACY_API',
247248
text: notifText,

src/commands/hardis/org/diagnose/licenses.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { uxLog } from '../../../../common/utils/index.js';
77
import { soqlQuery } from '../../../../common/utils/apiUtils.js';
88
import { generateCsvFile, generateReportPath } from '../../../../common/utils/filesUtils.js';
99
import { NotifProvider } from '../../../../common/notifProvider/index.js';
10+
import { setConnectionVariables } from '../../../../common/utils/orgUtils.js';
1011

1112
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
1213
const messages = Messages.loadMessages('sfdx-hardis', 'org');
@@ -121,7 +122,7 @@ export default class DiagnoseUnusedUsers extends SfCommand<any> {
121122
this.outputFile = await generateReportPath('licenses', this.outputFile);
122123
this.outputFilesRes = await generateCsvFile(this.licenses, this.outputFile);
123124

124-
globalThis.jsForceConn = flags['target-org']?.getConnection(); // Required for some notifications providers like Email
125+
await setConnectionVariables(flags['target-org']?.getConnection());// Required for some notifications providers like Email
125126
await NotifProvider.postNotifications({
126127
type: 'LICENSES',
127128
text: '',

0 commit comments

Comments
 (0)